OpenNLP の名前付きエンティティ認識機能のトレーニングをしたかったのです。http://opennlp.apache.org/documentation/1.5.2-incubating/manual/opennlp.html#tools.namefindに従ってコードを書きました
「number」のトレーニングを試みる簡単な例から始め、次のようにトレーニング ファイル内のすべての \d+ をマークしました。
In <START:number> 1941 <END>, Paramount Pictures produced a movie version of the play.
コードは次のとおりです。
static String markedFile = "C:/MyStuff/eclipse_workspace/OpenNlpTest/src/NameFinderTraining/en-ner-number-marked.train";
static String modelFile = "C:/MyStuff/eclipse_workspace/OpenNlpTest/src/NameFinderTraining/en-ner-number-marked.bin";
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception
{
Charset charset = Charset.forName("UTF-8");
ObjectStream<String> lineStream =
new PlainTextByLineStream(new FileInputStream( markedFile), charset);
ObjectStream<NameSample> sampleStream = new NameSampleDataStream(lineStream);
TokenNameFinderModel model;
try
{
model = NameFinderME.train("en", "person", sampleStream,
Collections.<String, Object>emptyMap(), 100, 5);
}
finally
{
sampleStream.close();
}
BufferedOutputStream modelOut = null;
try
{
modelOut = new BufferedOutputStream(new FileOutputStream(modelFile));
model.serialize(modelOut);
}
finally
{
if (modelOut != null)
modelOut.close();
}
}
次の例外が発生しました。
Computing event counts... java.io.IOException: Found unexpected annotation while handling a name sequence: until the ###<START:number>### 1950 <END>s
私の推測では、「number」はデフォルトの注釈リストに含まれていません。私は何をすべきか?「カスタム注釈」が必要な場合は、誰かが例を教えてくれます。