我正在使用StanfordCoreNLP API接口以编程方式执行一些基本的NLP。我需要在我自己的语料库上训练一个模型,但是我想使用StanfordCoreNLP
界面来完成它,因为它在幕后处理了很多干技术,我不需要那么专业化。
我已经培训了一个我想用于NER的CRFClassifier,序列化为一个文件。根据文档,我认为以下内容可行,但它似乎没有找到我的模型,而是barfs无法找到标准模型(我不知道为什么我没有这些模型文件,但我不关心它,因为我不想使用它们):
// String constants
final String serializedClassifierFilename = "/absolute/path/to/model.ser.gz";
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, ner");
props.setProperty("ner.models", serializedClassifierFilename);
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String fileContents = IOUtils.slurpFileNoExceptions("test.txt");
Annotation document = new Annotation(fileContents);
结果:
Adding annotator tokenize
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
Adding annotator ssplit
Adding annotator ner
Loading classifier from /path/build/edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... java.io.FileNotFoundException: edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1554)
等等。
我知道我没有内置模型(再次,不知道为什么......我只是克隆了他们的git repo并用ant compile
编译。无论如何,我不想使用他们的模型无论如何,我想使用我训练过的那个。
如何让StanfordCoreNLP界面在ner
步骤中使用我的模型?有可能吗?不可能吗?
答案 0 :(得分:2)
属性名称为ner.model
,而不是ner.models
,因此您的代码仍在尝试加载默认模型。
如果在某处记录错误,请告诉我。