【发布时间】:2016-04-24 05:55:21
【问题描述】:
有人能想出一种方法来加快我的 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);
然后我从我的控制器调用管道:
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);
...
}
我已经分析了代码——Annotation annotation = pipeline.process(text) 行,这是 CoreNLP 的主要处理调用,非常慢。对我的控制器进行 100 次调用的请求平均需要 1.07 秒。注释每次调用大约需要 7 毫秒。我需要将其减少到 ~2ms。
我无法删除任何注释器,因为情感依赖于所有注释器。我已经在使用 Shift-Reduce Constituency Parser,因为它比默认的 Context-Free Grammar Parser 快得多。
我可以调整任何其他参数来显着加快速度吗?
【问题讨论】:
-
我假设您使用默认模型,如果没有大型注释语料库,这很可能是不可行的,但您很可能可以针对您的领域重新训练较小的模型。
标签: java performance optimization stanford-nlp sentiment-analysis