kel*_*raj 6 java optimization performance stanford-nlp sentiment-analysis
谁能想到加快我的CoreNLP情绪分析的方法(下图)?
我在服务器启动时初始化CoreNLP管道:
// Initialize the CoreNLP text processing pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;
// Set text processing pipeline's annotators
props.setProperty("annotators", "tokenize, ssplit, pos, parse, sentiment");
// Use Shift-Reduce Constituency Parsing (O(n),
// http://nlp.stanford.edu/software/srparser.shtml) vs CoreNLP's default
// Probabilistic Context-Free Grammar Parsing (O(n^3))
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
Run Code Online (Sandbox Code Playgroud)
然后我从我的控制器调用管道:
String text = 'A sample string.'
Annotation annotation = pipeline.process(text);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
...
}
Run Code Online (Sandbox Code Playgroud)
我已经分析了代码 - 这条线Annotation annotation = pipeline.process(text)是CoreNLP的主要处理调用,非常慢.对我的控制器进行100次调用的请求平均需要1.07秒.注释每次调用大约需要7毫秒.我需要将其减少到~2ms.
我无法删除任何注释器,因为情绪依赖于所有这些注释器.我已经在使用Shift-Reduce选区解析器,因为它比默认的Context-Free Grammar Parser快得多.
我可以调整任何其他参数来显着提高速度吗?
小智 0
有同样的问题。我也尝试过 SR Beam,它比 PCFG 还要慢!根据斯坦福大学的基准测试,SR Beam 应该比 PCFG 快得多,仅比 SR 慢一点。
我想除了使用 SR 解析器而不是 PCFG 之外,提高速度的唯一剩余方法可能是使用分词器选项......