aga*_*wav 0 java performance stanford-nlp
我正在Windows中进行NLP项目,问题是每当我从命令提示符运行Stanford CoreNLP时,生成给定输入文本文件的XML输出大约需要14-15秒.我认为这个问题是因为库需要花费很多时间才能加载.可以请有人解释问题是什么,如何解决这个问题,因为这个时间问题对我的项目来说是个大问题?
Stanford CoreNLP使用各种组件的大型模型参数文件.是的,他们需要很多时间来加载.你想要做的只是启动程序一次,然后提供大量的文本.
你如何做到这一点取决于你在做什么:
2016年更新:文档页面上有关于此的更多信息了解内存和时间使用情况
克里斯托弗是对的,这是解决方案之一:
import java.util.Properties;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
public class SentimentAnalyzer {
private StanfordCoreNLP pipeline;
public void initializeCoreNLP() {
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment");
pipeline = new StanfordCoreNLP(props);
}
public T getSentiment(String text) {
...
Annotation annotation= new Annotation(text);
pipeline.annotate(annotation);
...
return ...
}
public static void main(String[] argv) {
SentimentAnalyzer sentimentAnalyzer = new SentimentAnalyzer();
sentimentAnalyzer.initializeCoreNLP(); // run this only once
T t = sentimentAnalyzer.getSentiment("put text here..."); // run this multiple times
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4509 次 |
| 最近记录: |