Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Stanford nlp 如何获得CoreNLP情绪的分数分布值?_Stanford Nlp_Stanford Nlp Server - Fatal编程技术网

Stanford nlp 如何获得CoreNLP情绪的分数分布值?

Stanford nlp 如何获得CoreNLP情绪的分数分布值?,stanford-nlp,stanford-nlp-server,Stanford Nlp,Stanford Nlp Server,我已经在我的ubuntu实例上安装了CoreNLP服务器,它工作正常。我对情绪模块更感兴趣,目前我得到的是 { sentimentValue: "2", sentiment: "Neutral" } 我需要的是分数分布值,如您所见: 我遗漏了什么,或者如何获得这些数据 谢谢您需要从带注释的句子中通过感伤CoreAnnotations.感伤AnnotatedTree.class获取a树对象。然后,您可以通过rnnconconreationnotations类获得预测。我在下面编写了以下独立的演示

我已经在我的ubuntu实例上安装了CoreNLP服务器,它工作正常。我对情绪模块更感兴趣,目前我得到的是

{
sentimentValue: "2",
sentiment: "Neutral"
}
我需要的是分数分布值,如您所见:

我遗漏了什么,或者如何获得这些数据


谢谢

您需要从带注释的句子中通过
感伤CoreAnnotations.感伤AnnotatedTree.class
获取a树对象。然后,您可以通过
rnnconconreationnotations
类获得预测。我在下面编写了以下独立的演示代码,展示了如何获得CoreNLP情绪预测的每个标签的分数

import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.ejml.simple.SimpleMatrix;

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;

public class DemoSentiment {
    public static void main(String[] args) {
        final List<String> texts = Arrays.asList("I am happy.", "This is a neutral sentence.", "I am very angry.");
        final Properties props = new Properties();
        props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
        final StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        for (String text : texts) {
            final Annotation doc = new Annotation(text);
            pipeline.annotate(doc);
            for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
                final Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
                final SimpleMatrix sm = RNNCoreAnnotations.getPredictions(tree);
                final String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
                System.out.println("sentence:  "+sentence);
                System.out.println("sentiment: "+sentiment);
                System.out.println("matrix:    "+sm);
            }
        }
    }
}
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.ejml.simple.SimpleMatrix;

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;

public class DemoSentiment {
    public static void main(String[] args) {
        final List<String> texts = Arrays.asList("I am happy.", "This is a neutral sentence.", "I am very angry.");
        final Properties props = new Properties();
        props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
        final StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        for (String text : texts) {
            final Annotation doc = new Annotation(text);
            pipeline.annotate(doc);
            for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) {
                final Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
                final SimpleMatrix sm = RNNCoreAnnotations.getPredictions(tree);
                final String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
                System.out.println("sentence:  "+sentence);
                System.out.println("sentiment: "+sentiment);
                System.out.println("matrix:    "+sm);
            }
        }
    }
}
sentence:  I am happy.
sentiment: Positive
matrix:    Type = dense , numRows = 5 , numCols = 1
0.016  
0.037  
0.132  
0.618  
0.196  

sentence:  This is a neutral sentence.
sentiment: Neutral
matrix:    Type = dense , numRows = 5 , numCols = 1
0.001  
0.007  
0.952  
0.039  
0.001  

sentence:  I am very angry.
sentiment: Negative
matrix:    Type = dense , numRows = 5 , numCols = 1
0.166  
0.652  
0.142  
0.028  
0.012