【问题标题】:Speed up CoreNLP Sentiment Analysis加速 CoreNLP 情绪分析
【发布时间】: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


【解决方案1】:

有同样的问题。我也试过 SR Beam,它比 PCFG 还要慢!根据斯坦福基准,SR Beam 应该比 PCFG 快得多,并且只比 SR 慢一点。

我想除了使用 SR 解析器而不是 PCFG 之外,提高速度的唯一剩余方法可能是使用标记器选项...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    相关资源
    最近更新 更多