IT源码网

java之斯坦福情绪分析偏向负面

telwanggs 2024年12月31日 程序员 51 0

我正在对现有的情绪分析应用程序进行一些研究。我目前正在查看斯坦福 CoreNlp/情绪分析 3.8.0,我在测试数据中注意到预测似乎偏向负面。以下是一些返回负面结果的示例:

  1. 纽约是我最终想要度过我的教学生涯的地方,这个机会太好了,不容拒绝。 - 负面
  2. 我知道成为一名高效且有影响力的教师是我的责任,但我渴望在课前、课中和课后投入时间,以确保我是学生的可用资源。 - 负面
  3. 根据我的个人经验,我在类里面学到了许多必要的生活技能,对我影响最大的老师是我的激励者和支持者。 - 负面

我检查了一下,只有一种可能的模型可以使用(所以我认为没有任何杠杆可以插入 - 我不想训练模型)。我可以使用不同的/更好的(也许?) POS,这可以给我一个不同的预测,但我有点困惑,因为我读到的关于斯坦福大学图书馆的所有博客/评论都是积极的,而我的结果却很糟糕。我错过了什么吗?

代码:

    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize, ssplit, parse, sentiment"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
    Annotation document = pipeline.process(text); 
    pipeline.annotate(document); 
 
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); 
    int mainSentiment=0; int longest = 0; 
    SimpleMatrix matrix = null; 
    for (CoreMap sentence : sentences) { 
        String s_sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class); 
 
        Tree tree = sentence 
                .get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); 
        int sentiment = RNNCoreAnnotations.getPredictedClass(tree); 
        matrix = RNNCoreAnnotations.getPredictions(tree); 
 
        System.out.println(sentence); 
        System.out.println(sentiment + "-" +s_sentiment + "\t" + matrix.elementMaxAbs()); 
    } 

可能的分数值: 0 非常负面 1 负面 2 中性 3 积极 4 非常积极

如果您在生产应用程序中使用此库,您是否发现其结果可以可靠地插入操作?

请您参考如下方法:

首先,从版本3.3.1开始不只有一个模型可以作为参数传递给 the option sentiment.model而是两个(遗憾的是,网站上似乎没有提到这一点):

  • 四类模型(非常负面负面中性正面非常正面)edu/stanford/nlp/models/sentiment/sentiment.ser.gz
  • 二类模型(负面中性正面)edu/stanford/nlp/models/sentiment/sentiment.binary.ser.gz

这不是标准模型集的一部分,而是 the additional models-english model ;为了使用它,您需要获取它,这可以更好地记录下来。适当的 Maven 工件依赖项是

<dependency> 
        <groupId>edu.stanford.nlp</groupId> 
        <artifactId>stanford-corenlp</artifactId> 
        <version>${stanford-corenlp.version}</version> 
        <classifier>models-english</classifier> 
        <scope>runtime</scope> 
</dependency> 

their 2013 paper 中所述,他们使用电影评论语料库来创建模型,并且这些数据很可能对于分析您所使用的语言类型来说不是最佳的:例如,looking for too good to refuse in their corpus gives no results at all尽管它是一个相对常见的术语。

我自己也尝试使用他们预先训练的模型来分析 session 语言,结果不错,但也并不令人惊讶:仅创建积极和消极模式列表并在我的文本中查找它们的准确性与使用情绪分析器没有显着不同。


评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!