gpt4 book ai didi

java - 在 stanford-nlp 中训练 NER 模型

转载 作者:行者123 更新时间:2023-12-01 09:46:08 25 4
gpt4 key购买 nike

我一直在尝试使用 stanford Core NLP。我希望训练我自己的 NER 模型。 SO 论坛和官方网站描述了使用属性文件来执行此操作。我该如何通过 API 来做到这一点?

Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment, regexner");
props.setProperty("regexner.mapping", "resources/customRegexNER.txt");

StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

String processedQuestion = "Who is the prime minister of Australia?"

//Annotation annotation = pipeline.process(processedQuestion);
Annotation document = new Annotation(processedQuestion);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for (CoreMap sentence : sentences) {

// To get the tokens for the parsed sentence
for (CoreMap tokens : sentence.get(TokensAnnotation.class)) {
String token = tokens.get(TextAnnotation.class);
String POS = tokens.get(PartOfSpeechAnnotation.class);
String NER = tokens.get(NamedEntityTagAnnotation.class);
String Sentiment = tokens.get(SentimentClass.class);
String lemma = tokens.get(LemmaAnnotation.class);
  1. 如何以及在哪里添加 Prop 文件?
  2. N-gram 标记化(例如,总理被视为单个标记,稍后该标记被传递给 POS、NER,而不是传递两个标记(总理和部长))?

最佳答案

我认为它可以与该代码一起使用:

val props = new Properties()
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, regexner")
props.put("ner.model", "/your/path/ner-model.ser.gz");
val pipeline = new StanfordCoreNLP(props)

关于java - 在 stanford-nlp 中训练 NER 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38013103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com