ML.NET:输入列'AnswerFeaturized_CharExtractor'的模式不匹配:预期的Single的预期Single或已知大小的向量,得到Vector <Single>

时间:2019-08-01 13:11:37

标签: c# machine-learning ml.net

我试图在ML.NET中创建一个机器学习模型,该模型根据用户输入的答案预测成绩。 以下是代码:

    private static string _appPath => Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
        private static string _trainDataPath => Path.Combine(_appPath, "..", "..", "..", "Data", "GradeTrain.csv");

        static void Main(string[] args)
        {
            _mlContext = new MLContext(seed: 0);
            _trainingDataView = _mlContext.Data.LoadFromTextFile<InputData>(_trainDataPath, hasHeader: true);           
            var pipeline = ProcessData();
            var trainingPipeline = BuildAndTrainModel(_trainingDataView, pipeline);            
            Evaluate(_trainingDataView.Schema);          
        }

        public static IEstimator<ITransformer> ProcessData()
        {
            var pipeline = _mlContext.Transforms.Conversion.MapValueToKey(inputColumnName: "Grade", outputColumnName: "Label").Append(_mlContext.Transforms.Text.FeaturizeText(inputColumnName: "QuestionID", outputColumnName: "QuestionIDFeaturized")).Append(_mlContext.Transforms.Text.FeaturizeText(inputColumnName: "Answer", outputColumnName: "AnswerFeaturized")).Append(_mlContext.Transforms.Concatenate("Features", "QuestionIDFeaturized", "AnswerFeaturized")).AppendCacheCheckpoint(_mlContext);
            return pipeline;
        }
      public static IEstimator<ITransformer> BuildAndTrainModel(IDataView trainingDataView, IEstimator<ITransformer> pipeline)
        {
            var trainingPipeline = pipeline.Append(_mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features"))                .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));            
            _trainedModel = trainingPipeline.Fit(trainingDataView);
            _predEngine = _mlContext.Model.CreatePredictionEngine<InputData, answerGradePrediction>(_trainedModel);
            InputData issue = new InputData()
            {
                QuestionID = "HOUSES",
                Answer = "The upper house is called Rajya sabha and the lower house is called Lok sabha"
            };
            var prediction = _predEngine.Predict(issue);           
            return trainingPipeline;
        }

输入类的代码

public class InputData
{
    [LoadColumn(0)]
    public string QuestionID { get; set; }
    [LoadColumn(1)]
    public string Answer { get; set; }
    [LoadColumn(2)]
    public string Grade { get; set; }
}

这会在“拟合函数”中产生以下错误:

System.ArgumentOutOfRangeException: 'Schema mismatch for input column 'AnswerFeaturized_CharExtractor': expected Expected Single or known-size vector of Single, got Vector<Single>
Parameter name: inputSchema'

有什么想法吗?

0 个答案:

没有答案