首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加速CoreNLP情感分析

加速CoreNLP情感分析
EN

Stack Overflow用户
提问于 2016-01-19 06:30:01
回答 1查看 662关注 0票数 6

谁能想出一种方法来加速我的CoreNLP情感分析(见下文)?

我在服务器启动时初始化一次CoreNLP管道:

代码语言:javascript
复制
// 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);

然后我从我的控制器调用管道:

代码语言:javascript
复制
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成分解析器了,因为它比默认的上下文无关语法解析器快得多。

还有没有其他的参数可以让我大大提高速度呢?

EN

回答 1

Stack Overflow用户

发布于 2017-12-05 06:04:21

有同样的问题。我也试过SR光束,它甚至比PCFG还要慢!根据斯坦福的基准,SR波束应该比PCFG快得多,而只比SR稍微慢一点。

我猜除了使用SR解析器而不是PCFG之外,提高速度的唯一方法可能是使用tokenizer选项……

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34865277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档