OpenNLP MaxEnt를 사용하여 내 자신의 모델을 작성하고 싶습니다. ContextGenerator 및 EventStream 인터페이스 (문서에 언급 된대로)를 구현하고 싶습니다. OpenNLP Chuncker, Postagger 및 NameFinder에 대한 이러한 구현을 살펴 보았지만 모든 구현에서는 'Pair'가 사용되지 않으며 해당 ContextGenerator가 수행하는 작업을 이해하지 못하는 코드를 살펴 보았습니다. 내가 만들 모델은 각 토큰에 대해 POS 태그를보고 각 토큰을 RoomNumber 또는 RoomNumber로 분류합니다. 이 모델에 대해 ContextGenerator 및 EventStream 코딩을 어떻게 시작해야합니까? 컨텍스트가 무엇인지, 어떤 기능이 있는지는 알지만 ContextGenerator의 기능과 EvenStream의 기능에 대해서는 알지 못합니다. openNLP maxent page를 보았지만 도움이되지 않습니다. 이걸 이해하게 도와주세요, 고마워요.OpenNLP MaxEnt - ContextGenerator 및 EventStream
1
A
답변
0
명시 적으로 ContextGenerator
을 사용하지는 않지만 다음 코드가 도움이 될 수 있습니다. 실제로 에는 BasicContextGenerator
이 사용되며 각 입력 문자열을 기능 목록으로 분할합니다.
문자열 "a=1 b=2 c=1"
은 "a=1"
, "b=2"
및 "c=1"
의 세 가지 기능으로 나뉩니다.
package opennlptest;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import opennlp.maxent.GIS;
import opennlp.model.Event;
import opennlp.model.EventStream;
import opennlp.model.ListEventStream;
import opennlp.model.MaxentModel;
public class TestMaxentEvents {
static Event createEvent(String outcome, String... context) {
return new Event(outcome, context);
}
public static void main(String[] args) throws IOException {
// here are the input training samples
List<Event> samples = Arrays.asList(new Event[] {
// outcome + context
createEvent("c=1", "a=1", "b=1"),
createEvent("c=1", "a=1", "b=0"),
createEvent("c=0", "a=0", "b=1"),
createEvent("c=0", "a=0", "b=0")
});
// training the model
EventStream stream = new ListEventStream(samples);
MaxentModel model = GIS.trainModel(stream);
// using the trained model to predict the outcome given the context
String[] context = {"a=1", "b=0"};
double[] outcomeProbs = model.eval(context);
String outcome = model.getBestOutcome(outcomeProbs);
System.out.println(outcome); // output: c=1
}
}
순수한 Maxent을 사용하는 데 관심이 : 당신은 그냥 분류를 위해 그것을 사용하는 다음 모델을 학습하는 Maxent API를 사용하려면
, 당신은 나를 위해 일한 다음과 같은 방법을 사용할 수 있습니다 OpenNLP의 분류 기준이나 maxent를 사용하는 상위 API? –