Exemple #1
0
 public LemmatizerModel(string languageCode, IMaxentModel lemmatizerModel, LemmatizerFactory factory)
     : this(languageCode, lemmatizerModel, null, factory)
 {
 }
Exemple #2
0
        public LemmatizerModel(string languageCode, IMaxentModel lemmatizerModel, int beamSize, Dictionary <string, string> manifestInfoEntries, LemmatizerFactory factory)
            : base(ComponentName, languageCode, manifestInfoEntries, factory)
        {
            artifactMap.Add(ModelEntry, lemmatizerModel);

            Manifest[Parameters.BeamSize] = beamSize.ToString(CultureInfo.InvariantCulture);

            CheckArtifactMap();
        }
Exemple #3
0
 public LemmatizerModel(string languageCode, IMaxentModel lemmatizerModel, Dictionary <string, string> manifestInfoEntries, LemmatizerFactory factory)
     : this(languageCode, lemmatizerModel, LemmatizerME.DefaultBeamSize, manifestInfoEntries, factory)
 {
 }
Exemple #4
0
 public LemmatizerModel(string languageCode, ISequenceClassificationModel <string> lemmatizerModel, Dictionary <string, string> manifestInfoEntries, LemmatizerFactory factory)
     : base(ComponentName, languageCode, manifestInfoEntries, factory)
 {
     artifactMap.Add(ModelEntry, lemmatizerModel);
     CheckArtifactMap();
 }
        /// <summary>
        /// Trains a lemmatizer model with the given parameters.
        /// </summary>
        /// <param name="languageCode">The language code.</param>
        /// <param name="samples">The data samples.</param>
        /// <param name="parameters">The machine learnable parameters.</param>
        /// <param name="factory">The sentence detector factory.</param>
        /// <param name="monitor">
        /// A evaluation monitor that can be used to listen the messages during the training or it can cancel the training
        /// operation.
        /// This argument can be a <c>null</c> value.
        /// </param>
        /// <returns>The trained <see cref="LemmatizerModel" /> object.</returns>
        /// <exception cref="System.InvalidOperationException">The trainer was not specified.</exception>
        /// <exception cref="System.NotSupportedException">Trainer type is not supported.</exception>
        public static LemmatizerModel Train(string languageCode, IObjectStream <LemmaSample> samples, TrainingParameters parameters, LemmatizerFactory factory, Monitor monitor)
        {
            var manifestInfoEntries = new Dictionary <string, string>();
            var beamSize            = parameters.Get(Parameters.BeamSize, DefaultBeamSize);
            var cg = factory.GetContextGenerator();


            var trainerType = TrainerFactory.GetTrainerType(parameters);

            if (!trainerType.HasValue)
            {
                throw new InvalidOperationException("The trainer was not specified.");
            }


            IMaxentModel model = null;

            ML.Model.ISequenceClassificationModel <string> seqModel = null;

            switch (trainerType)
            {
            case TrainerType.EventModelTrainer:
                var s1 = new LemmaSampleEventStream(samples, cg);
                var t1 = TrainerFactory.GetEventTrainer(parameters, manifestInfoEntries, monitor);

                model = t1.Train(s1);
                break;

            case TrainerType.EventModelSequenceTrainer:
                var s2 = new LemmaSampleSequenceStream(samples, cg);
                var t2 = TrainerFactory.GetEventModelSequenceTrainer(parameters, manifestInfoEntries, monitor);

                model = t2.Train(s2);
                break;

            case TrainerType.SequenceTrainer:
                var s3 = new LemmaSampleSequenceStream(samples, cg);
                var t3 = TrainerFactory.GetSequenceModelTrainer(parameters, manifestInfoEntries, monitor);

                seqModel = t3.Train(s3);
                break;

            default:
                throw new NotSupportedException("Trainer type is not supported.");
            }

            return(model != null
                ? new LemmatizerModel(languageCode, model, beamSize, manifestInfoEntries, factory)
                : new LemmatizerModel(languageCode, seqModel, manifestInfoEntries, factory));
        }
 /// <summary>
 /// Trains a lemmatizer model with the given parameters.
 /// </summary>
 /// <param name="languageCode">The language code.</param>
 /// <param name="samples">The data samples.</param>
 /// <param name="parameters">The machine learnable parameters.</param>
 /// <param name="factory">The sentence detector factory.</param>
 /// <returns>The trained <see cref="LemmatizerModel" /> object.</returns>
 /// <exception cref="System.InvalidOperationException">The trainer was not specified.</exception>
 /// <exception cref="System.NotSupportedException">Trainer type is not supported.</exception>
 public static LemmatizerModel Train(string languageCode, IObjectStream <LemmaSample> samples, TrainingParameters parameters, LemmatizerFactory factory)
 {
     return(Train(languageCode, samples, parameters, factory, null));
 }