2017-11-22 21 views
0

現在、クラシファイアのモデルをトレーニングしています。昨日、作成した分類モデルをテストすると、より正確になることがわかりました。モデルをテストする方法をインターネットで検索しました:testing openNLP model。しかし、私はそれを働かせることはできません。なぜなら私は1.5の代わりにOpenNLPバージョン1.83を使っているからです。誰でも私のモデルをOpenNLPのこのバージョンで適切にテストする方法を教えてもらえますか?OpenNLPクラシファイアモデルをテストする

ありがとうございます。

public static DoccatModel trainClassifier() throws IOException 
    { 
     // read the training data 
     final int iterations = 100; 
     InputStreamFactory dataIn = new MarkableFileInputStreamFactory(new File("src/main/resources/trainingSets/trainingssetTest.txt")); 
     ObjectStream<String> lineStream = new PlainTextByLineStream(dataIn, "UTF-8"); 
     ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream); 

     // define the training parameters 
     TrainingParameters params = new TrainingParameters(); 
     params.put(TrainingParameters.ITERATIONS_PARAM, iterations+""); 
     params.put(TrainingParameters.CUTOFF_PARAM, 0+""); 
     params.put(AbstractTrainer.ALGORITHM_PARAM, NaiveBayesTrainer.NAIVE_BAYES_VALUE); 

     // create a model from traning data 
     DoccatModel model = DocumentCategorizerME.train("NL", sampleStream, params, new DoccatFactory()); 

     return model; 
    } 

答えて

1

私はあなたのモデルをテストするには、2つの方法を考えることができます。

は、以下の私のモデルのトレーニング方法イムです。いずれにせよ、あなたは注釈付き文書を持っている必要があります(私は本当に専門家に分類された注釈付きです)。

最初の方法は、opennlp DocCatEvaluatorの使用です。構文は

opennlp DoccatEvaluator -model model -data sampleData 

と同類なものになるだろうあなたれるsampleDataのフォーマットは

OUTCOME <document text....> 

文書は、改行文字で区切られていなければなりません。

第2の方法は、DocumentCategorizerを作成することです。ような何か: (モデルは、あなたの質問からDocCatモデルである)

私はここにコードを入力した構文エラーまたは2(IまたはSOコミュニティは修正することができますいずれか)が、アイデアがあるかもしれませんので
DocumentCategorizer categorizer = new DocumentCategorizerME(model); 

// could also use: Tokenizer tokenizer = new TokenizerME(tokenizerModel) 
Tokenizer tokenizer = WhitespaceTokenizer.INSTANCE(); 

// linesample is like in your question... 
for(String sample=linesample.read(); sample != null; sample=linesample.read()){ 
    String[] tokens = tokenizer.tokenize(sample); 
    double[] outcomeProb = categorizer.categorize(tokens); 
    String sampleOutcome = categorizer.getBestCategory(outcomeProb); 

    // check if the outcome is right... 
    // keep track of # right and wrong... 
} 
// calculate agreement metric of your choice 

トークン化、ドキュメントカテゴライザでの実行、結果の追跡は、モデルを評価する方法です。

希望すると...

関連する問題