加速CoreNLP情感分析

6

你能想到加速以下的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 毫秒。我需要将其减少到 ~2 毫秒。
我不能删除任何注释器,因为情感依赖于所有注释器。我已经使用 Shift-Reduce Constituency Parser ,因为它比默认的 Context-Free Grammar Parser 快得多。
还有其他参数可以调整以显着加快处理速度吗?

我假设你使用默认模型,如果没有大量的注释语料库,那么很可能是不可行的,但是你可以重新训练针对你领域的较小模型。 - Josep Valls
1个回答

0

遇到了同样的问题。我也尝试了SR Beam,但它比PCFG还要慢!根据斯坦福基准测试,SR Beam应该比PCFG快得多,只比SR略慢。

我想除了使用SR解析器而不是PCFG之外,唯一剩下的提高速度的方法可能就是调整分词器选项了...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接