"Enhancing" CoreNLP 情感分析结果

"Enhancing" CoreNLP Sentiment Analysis Results

我正在尝试使用 CoreNLP (Java) 对大量产品评论进行情感分析。总的来说,我发现分析的准确性非常好。根据我的阅读,我使用的模型最初是使用电影评论创建的(我认为),因此它不是 100% 适合分析产品评论。我想知道 "enhancing" 分析准确性的最佳方法。

我主要考虑的是,除了产品评论的文字,我还有一个用户提供的星级。值范围从 1-5,1 星是最低的。我希望有一种方法可以在生成情绪评分时考虑星级评分,因为它可以更准确地反映用户对特定产品的感受。有没有一种方法可以最好地将星级评分因素纳入 CoreNLP 中的情绪分析评分?我的分析代码看起来像这样:

List<ProductReview> reviews = this.reviewRepository.findAll();
        for (ProductReview review : reviews) {
            Properties props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref, sentiment");
            props.put("ner.model", "edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz");

            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

            int starRating = review.getStarRating();
            String reviewText = review.getTitle() + " : " + review.getReviewText();
            if (!StringUtils.isEmpty(reviewText)) {
                int longest = 0;
                int mainSentiment = 0;
                Annotation annotation = pipeline.process(reviewText);
                String sentimentStr = null;
                List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
                for (CoreMap sentence : sentences) {
                    Tree sentimentTree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);

                    int sentiment = RNNCoreAnnotations.getPredictedClass(sentimentTree) - 2;
                    String partText = sentence.toString();
                    if (partText.length() > longest) {
                        mainSentiment = sentiment;
                        sentimentStr = sentence.get(SentimentCoreAnnotations.SentimentClass.class);

                        longest = partText.length();
                    }
                }
            }
        }

我怎样才能最好地将星级评分(或其他信息,例如对最有用的产品评论的投票等)纳入 CoreNLP 执行的分析?这是我必须单独做的事情吗?或者有没有办法将额外的数据直接合并到情绪分析引擎中?

可以进行一些改进。

/1。 即兴训练集和情境情感分析: 某些功能可能在电影评论上下文中被归类为正面,但在产品评论上下文中可能被归类为负面。您应该根据您的上下文重新训练您的数据。指定的方法 here

Models can be retrained using the following command using the PTB format dataset:

java -mx8g edu.stanford.nlp.sentiment.SentimentTraining -numHid 25 -trainPath train.txt -devPath dev.txt -train -model model.ser.gz

可以找到关于训练数据集的很好的讨论here

/2.获取上下文训练和测试数据: 您的产品评论数据可以作为训练集和测试集。 Select 极端极性的评论(1 星 POOREST,5 星 GREAT)作为你的训练数据,为了进一步改进内容,你可以 select 1 星和 5 星评论,这些评论被标记为有帮助由社区。 使用此数据生成的 PTB 数据集将评论分类为正面和负面(使用 2-3-4 星级评论很难达到中性,因为它们会引入噪音)。

/3。使用 80% 的数据集作为训练集,20% 作为测试集。 1 星评级的评论大多应归类为负面,而 5 星评级的评论大多应归类为正面。 Post 这个,你可以使用训练好的模型来分析其他评论的情绪,你的情绪得分(负面情绪为 0,非常正面情绪为 5,或 -1负面为 +1 为非常正面) 将与随该评论一起提供的实际星级评定 呈正相关。如果存在 情绪差异 ,例如文本评论显示为正面情绪,但评分为 1 星,您可能需要记录此类情况,并临时进行分类。

/4。 使用其他数据源和分类器进行改进Vader sentiment (in python ) is a very good classifier specially attuned for social media and things like product reviews. You may or may not chose to use it as a comparative classifier ( to cross match or have double set of your results, from corenlp+vader), but you can surely use its amazon reviews dataset as mentioned here

amazonReviewSnippets_GroundTruth.txt FORMAT: the file is tab delimited with ID, MEAN-SENTIMENT-RATING, and TEXT-SNIPPET

DESCRIPTION: includes 3,708 sentence-level snippets from 309 customer reviews on 5 different products. The reviews were originally used in Hu & Liu (2004); we added sentiment intensity ratings. The ID and MEAN-SENTIMENT-RATING correspond to the raw sentiment rating data provided in 'amazonReviewSnippets_anonDataRatings.txt' (described below).

amazonReviewSnippets_anonDataRatings.txt FORMAT: the file is tab delimited with ID, MEAN-SENTIMENT-RATING, STANDARD DEVIATION, and RAW-SENTIMENT-RATINGS

DESCRIPTION: Sentiment ratings from a minimum of 20 independent human raters (all pre-screened, trained, and quality checked for optimal inter-rater reliability).

数据集在此处的 tgz 文件中可用: https://github.com/cjhutto/vaderSentiment/blob/master/additional_resources/hutto_ICWSM_2014.tar.gz

它遵循模式reviewindex_part polarity review_snippet

1_19    -0.65   the button was probably accidentally pushed to cause the black screen in the first place.
1_20    2.85    but, if you're looking for my opinion of the apex dvd player, i love it!
1_21    1.75    it practically plays almost everything you give it.