2017-11-22 2 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

내가 모델을 테스트하는 두 가지 방법을 생각할 수 있습니다

다음은 내 모델을 훈련하는 방식 메신저입니다. 어느 쪽이든, 주석이 달린 문서가 있어야합니다 (필자는 전문가 분류를 의미합니다).

첫 번째 방법은 opennlp DocCatEvaluator를 사용하는 것입니다. 구문은 샘플 데이터의 형식은

OUTCOME <document text....> 

문서가 새 라인 문자로 분리되어 있어야한다

opennlp DoccatEvaluator -model model -data sampleData 

에 가까운 것이 될 것입니다.

두 번째 방법은 DocumentCategorizer을 만드는 것입니다. 같은 뭔가 : (이 모델은 질문에서 DocCat 모델입니다)

내가 여기에 코드를 입력 구문 오류 또는 두 (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 

데이터 분류, 토큰 화, 문서 분류기를 통한 실행 및 결과 추적은 모델 평가 방법입니다.

희망 하시겠습니까?