我正在尝试使用StanfordNLP对与给定主题相关的大块文本进行共指解析,并且尝试加载StanfordCoreNLP模型时,起初它在加载模型时完全用尽了内存,但现在仍在使用15分钟即可加载。
我有这样的代码:
public Map<Integer, CorefChain> getCoreferences(String text) {
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation(text);
pipeline.annotate(document);
return document.get(CorefCoreAnnotations.CorefChainAnnotation.class);
}
这是设计不可避免的吗?甚至在超过10秒的时间都不可接受的生产应用程序中,甚至可以像这样进行共参考解析吗?
是的,如果不在您的方法中实例化StanfordCoreNLP,它将更快。将其存储为类变量。
更具体地说,将以下内容移到方法之外:
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
希望能帮助到你!;)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句