/// <summary> /// Creates a new instance with default arguments for supervised training. /// </summary> /// <param name="builder">An optional action to change some params.</param> public static SupervisedArgs SupervisedDefaults(Action <SupervisedArgs> builder = null) { var result = new SupervisedArgs { LearningRate = 0.1, MaxCharNGrams = 0, MinCharNGrams = 0 }; builder?.Invoke(result); return(result); }
public void Train(string inputPath, string outputPath, SupervisedArgs args) { ValidatePaths(inputPath, outputPath, null); var argsStruct = new SupervisedArgsStruct { Epochs = args.Epochs, LearningRate = args.LearningRate, MaxCharNGrams = args.MaxCharNGrams, MinCharNGrams = args.MinCharNGrams, Verbose = args.Verbose, WordNGrams = args.WordNGrams, Threads = args.Threads ?? 0 }; CheckForErrors(TrainSupervised(_fastText, inputPath, outputPath, argsStruct, args.LabelPrefix)); _maxLabelLen = GetMaxLabelLength(_fastText); }
/// <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)); } }
/// <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); }
/// <summary> /// Trains a new supervised model. /// </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> /// <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) { Supervised(inputPath, outputPath, args, new AutotuneArgs()); }