【问题标题】:How to get overall sentiment for multiple sentences如何获得多个句子的整体情绪
【发布时间】:2014-02-24 21:10:16
【问题描述】:

你如何找到多个句子/一个段落/大段文本的聚合情绪。

下面的代码基于 github 斯坦福 CoreNLP 测试和各种示例,但我发现的所有内容都已完成情感分析,仅计算单个句子的情感。但我想要整个推文的情绪,不管里面有多少句子。

我能想到的唯一其他方法是为SentimentPipeline.main(String[]) 创建一个单独的线程并将文本提供给stdin,并在sdout 中收集整体情绪。我更希望能够使用我的代码使其更简单/更高效,但我没有找到任何东西。

另外,我不想像大多数人那样对 jar 进行系统调用,因为我每天要发送数百万条推文。每次加载资源的开销太大了。

Annotation document = new Annotation(text);
pipeline.annotate(document);

List<CoreMap> sentences = document.get(SentencesAnnotation.class);
        String output;
        for (CoreMap sentence : sentences) {
            // traversing the words in the current sentence a CoreLabel is a CoreMap with additional token-specific methods
             output = "";
            for (CoreLabel token : sentence.get(TokensAnnotation.class)) {

                // this is the text of the token
                String word = token.get(TextAnnotation.class);

                // this is the Parts Of Speech tag of the token (noun, verb, adjective etc)
                // String pos = token.get(PartOfSpeechAnnotation.class);

                // this is the NER label of the token
                String ne = token.get(NamedEntityTagAnnotation.class);
                if (!ne.contentEquals("O")) {
                    output = output + (ne + " " + word + " ");
                }
            }

            //**************Sentiment Analysis 
            Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
             String sentiment = RNNCoreAnnotations.getPredictedClass(tree);

【问题讨论】:

标签: java jar stanford-nlp sentiment-analysis


【解决方案1】:

stanford corenlp 中的情绪分析工具包是在句子级数据集上进行训练的。如果你需要一个文档级别的情感引擎,我认为在文档上训练一个新模型是一个更好的选择。您也可以尝试将句子逐句处理,并使用一些棘手的方法(例如平均、最大值)作为基线来测试它是如何工作的。

【讨论】:

  • 是的,我正在考虑将句子的情绪平均在一起,但我觉得这不会给出准确的表示。我认为我的方法是在一个新线程中调用SentimentPipeline.main(String[]),然后以某种方式在stdin 中抛出字符串并以这种方式获得情绪。
  • 以上答案是正确的。简而言之......它只是没有。这很奇怪,您会认为他们需要整体情绪分析。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-11
  • 2016-08-12
  • 2021-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-01
相关资源
最近更新 更多