コード例 #1
0
        public ClassifierResult PredictLabels(string sentence)
        {
            if (fastTextPredictionProcess == null)
            {
                throw new Exception("Sentence classifier was already disposed");
            }

            var preprocessedText = PreprocessSentence(sentence);

            ExecutableLauncher.SendInputLine(fastTextPredictionProcess, preprocessedText);
            var output = ExecutableLauncher.ReadOutputLine(fastTextPredictionProcess);

            string[] results = output.Split(' ');

            var result = new ClassifierResult();

            if (results.Length >= 2)
            {
                result.Label1 = results[0].Substring(9);
                result.Proba1 = float.Parse(results[1], CultureInfo.InvariantCulture.NumberFormat);
            }
            if (results.Length >= 4)
            {
                result.Label2 = results[2].Substring(9);
                result.Proba2 = float.Parse(results[3], CultureInfo.InvariantCulture.NumberFormat);
            }

            return(result);
        }
コード例 #2
0
 public void Dispose()
 {
     ExecutableLauncher.Kill(fastTextPredictionProcess);
     fastTextPredictionProcess = null;
 }
コード例 #3
0
 public SentenceClassifier(string modelFileName)
 {
     fastTextPredictionProcess = ExecutableLauncher.LaunchCommand(EXECUTABLE_PATH, "predict-prob " + modelFileName + " - 2", Path.GetFullPath(MODEL_DIR));
 }