Ejemplo n.º 1
0
 private void Load(string file)
 {
     try
     {
         var    formatter = new BinaryFormatter();
         Stream stream    = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
         _model = (MLP)formatter.Deserialize(stream);
         _model.Recover(_conf, _train);
         stream.Close();
     }
     catch
     {
         Console.WriteLine($"Model file doesn't exist, create a new model instead");
         _model = new MLP(_conf, _train);
     }
 }
Ejemplo n.º 2
0
        public ArcstdBiLstm(Config config)
        {
            _conf = config;
            Global.Logger.WriteLine(Config.Separator);
            config.PrintParameters();



            if (_conf.Mode == Config.RunMode.train && (!File.Exists(config.TrainFile) || !File.Exists(config.DevFile)))
            {
                Console.WriteLine(Config.Separator);
                Console.WriteLine("train or dev file not found");
                Status = false;
                //throw new FileNotFoundException("train or dev file not found");
                return;
            }


            _train = new DataSet(config.TrainFile, config.UseCpos, new RandomNumberGenerator(config.Seed));
            _train.PrintTreeStats();

            _dev = new DataSet(config.DevFile, config.UseCpos);
            _dev.PrintTreeStats(false);

            if (File.Exists(config.TestFile))
            {
                _test = new DataSet(config.TestFile, config.UseCpos);
                _test.PrintTreeStats(false);
            }
            else
            {
                _test = null;
            }

            _train.GenerateMappings(config.WordCutOff);
            if (_conf.Model != null && File.Exists(_conf.Model))
            {
                Load(_conf.Model);
            }
            else
            {
                _model = new MLP(_conf, _train);
            }
            Status = true;
        }