Example #1
0
        /// <summary>
        /// Trains a new supervised model. If <see cref="AutotuneArgs.ValidationFile"/> is specified, an automated
        /// hyperparameter search will be performed.
        /// </summary>
        /// <param name="inputPath">Path to a training set.</param>
        /// <param name="outputPath">Path to write the model to (excluding extension).</param>
        /// <param name="args">
        /// Training arguments. If <see cref="SupervisedArgs"/> is passed, a supervised model will be trained.
        /// If <see cref="QuantizedSupervisedArgs"/> is passed, model will be quantized after training.
        /// </param>
        /// <param name="autotuneArgs">Autotune arguments.</param>
        /// <param name="debug">Whether to write debug info.</param>
        /// <remarks>Trained model will consist of two files: .bin (main model) and .vec (word vectors).</remarks>
        internal void Supervised(string inputPath, string outputPath, SupervisedArgs args, AutotuneArgs autotuneArgs, bool debug)
        {
            ValidatePaths(inputPath, outputPath, args.PretrainedVectors);

            if (args.model != ModelName.Supervised)
            {
                _logger?.LogWarning($"{args.model} model type specified in a Supervised() call. Model type will be changed to Supervised.");
            }

            var quantizedArgs = args as QuantizedSupervisedArgs;

            if (!string.IsNullOrEmpty(autotuneArgs.ModelSize) && quantizedArgs == null)
            {
                throw new InvalidOperationException("You specified model size in autotuneArgs, but passed SupervisedArgs instance. Pass QuantizedSupervisedArgs instead.");
            }

            bool quantizeWithNoQuantTune = quantizedArgs != null && string.IsNullOrEmpty(autotuneArgs.ModelSize);

            var argsStruct = _mapper.Map <FastTextArgsStruct>(args);

            argsStruct.model = model_name.sup;

            var autotuneStruct = _mapper.Map <AutotuneArgsStruct>(autotuneArgs);

            CheckForErrors(Train(
                               _fastText,
                               inputPath,
                               quantizeWithNoQuantTune ? null : outputPath,
                               argsStruct,
                               autotuneStruct,
                               args.LabelPrefix,
                               args.PretrainedVectors,
                               debug));

            if (quantizeWithNoQuantTune)
            {
                Quantize(quantizedArgs, outputPath);
            }
            else
            {
                _maxLabelLen = CheckForErrors(GetMaxLabelLength(_fastText));
                ModelPath    = AdjustPath(outputPath, !string.IsNullOrEmpty(autotuneArgs.ModelSize));
            }
        }
Example #2
0
 /// <summary>
 /// Trains a new supervised model. If <see cref="AutotuneArgs.ValidationFile"/> is specified, an automated
 /// hyperparameter search will be performed.
 /// </summary>
 /// <param name="inputPath">Path to a training set.</param>
 /// <param name="outputPath">Path to write the model to (excluding extension).</param>
 /// <param name="args">
 /// Training arguments. If <see cref="SupervisedArgs"/> is passed, a supervised model will be trained.
 /// If <see cref="QuantizedSupervisedArgs"/> is passed, model will be quantized after training.
 /// </param>
 /// <param name="autotuneArgs">Autotune arguments.</param>
 /// <remarks>Trained model will consist of two files: .bin (main model) and .vec (word vectors).</remarks>
 public void Supervised(string inputPath, string outputPath, SupervisedArgs args, AutotuneArgs autotuneArgs)
 {
     Supervised(inputPath, outputPath, args, autotuneArgs, false);
 }