我一直在試圖找到一些參考資料,介紹如何使用自己的實體創建自定義模型,比如如果我想從文本中識別體育運動的名稱。如何做它?如何使用我自己的實體創建自定義模型
1
A
回答
0
try {
propFile = new File(System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/propfile.prop");
properties = new Properties();
properties.load(new FileInputStream(propFile));
String to = properties.getProperty("serializeTo");
properties.setProperty("serializeTo", "ner-customModel.ser.gz");
properties.setProperty("trainFile",System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/outputTokenized.tsv");
CRFClassifier crf = new CRFClassifier(properties);
crf.train();
String s2 = "apples are apples";
System.out.println(crf.classifyToString(s2));
crf.serializeClassifier(System.getProperty("user.dir") + "/src/edu/stanford/nlp/ie/crf/ner-customModel.ser.gz");
} catch (IOException e) {
e.printStackTrace();
}
並聲明培訓文件和屬性文件中的其他屬性。 這對我有用:)
1
斯坦福的工具通常對於幾個NLP任務來說工作很好,但根據我的經驗,在opennlp中訓練自己的模型要容易得多。如果這是你的一個選項(您標記你的問題「斯坦福 - NLP」,但也許你並不侷限於只使用),你可以找到一些不錯的文檔在這裏:https://opennlp.apache.org/documentation/1.5.3/manual/opennlp.html#tools.namefind.training.tool