我已成功训练关系提取器模型并创建了 .ser 文件。
但是,我遇到了一个问题:模型成功找到了关系,但如果其实体之一包含多个标记,则仅选择一个标记。 例如,对于名为 Friend_of 的关系,以及如下句子:
Sam Tarly's best friend is Jon Snow.
模型将在以下实体之间找到 Friend_of 类型的关系:
- 塔利
- 乔恩
这会导致我的测试将其标记为误报,并且整个模型会得到不好的分数。
我尝试使用相同的训练数据训练自定义 NER 模型,然后使用此自定义 NER 模型在我的 props 文件中使用以下属性来训练 RelationExtractor 模型:
trainUsePipelineNER=true
ner.model=path/to/custom-ner-model.ser.gz
但这并没有解决问题。
这只是训练数据不足的问题还是我在这里遗漏了什么?
这是我用来获取关系的 Java 代码:
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, depparse, relation");
props.put("sup.relation.model", "lib/custom-relation-model-pipeline.ser");
props.put("pos.ptb3Escaping", "false");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
List<Relation> foundRelations = new ArrayList<>();
for (String doc : documents) {
Annotation document = new Annotation(doc);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
List<RelationMention> relationMentions = sentence.get(MachineReadingAnnotations.RelationMentionsAnnotation.class);
for (RelationMention relation : relationMentions) {
foundRelations.add(new Relation(relation.getArg(0).getValue(), relation.getType(), relation.getArg(1).getValue()));
}
}
}
谢谢!
西蒙。
最佳答案
所以我进一步研究了 MachineReading 关系提取。
我认为您想用 getExtentString()
替换 getValue()
并看看是否有帮助。
我使用我们的默认模型运行了一个例句:
乔·史密斯在 Google 工作。
并且它工作正常。
关于nlp - 斯坦福关系提取器自定义模型仅选择关系实体的一个标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41982308/