Giter Club home page Giter Club logo

sentiment-analysis's Introduction

Sentiment Analysis using Stanford CoreNLP

This is a Java project for Sentiment Analysis using Stanford CoreNLP.

The Stanford CoreNLP provides statistical NLP, deep learning NLP, and rule-based NLP tools for major computational linguistics problems, which can be incorporated into applications with human language technology needs..

Sentiment Analysis

The underlying technology of this is based on a new type of Recursive Neural Network that builds on top of grammatical structures.

The Java documentation for stanford nlp can be found here.

The live Demo of Stanfod sentiment analysis.

How to build this project

  1. Download the project and import into Eclipse

  2. Set the build path which must have the following libraries

  • stanford-corenlp-3.8.0
  • ejml-0.23
  • stanford-corenlp-3.8.0-models
Note: The stanford-corenlp-3.8.0-models has all the trained models. It is not set in the build path of this project due to size constraint. 
Download the jar file from Stanford NLP site
  1. Run the MainApp.java file

All the dependencies can be downloaded from Stanford NLP site .

Code Explained

Initialize

 // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and sentiment
props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
StanfordCoreNLP pipeline; = new StanfordCoreNLP(props);

How to find the sentiment score

Run the Annotators on the text and then get the SentimentAnnotatedTree

// this is the parse tree of the current sentence
Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);

//print the sentiment score using RNNCoreAnnotations
System.out.println("Sentiment Score: " + RNNCoreAnnotations.getPredictedClass(tree));

How to find 5 classes of sentiment classification: very negative, negative, neutral, positive, and very positive.

// this matrix contains the confidences
SimpleMatrix sm = RNNCoreAnnotations.getPredictedClass(tree);

The estimated probability/confidence looks something like this from 'sm' object

Type = dense , numRows = 5 , numCols = 1
 0.111  
 0.758  
 0.087  
 0.035  
 0.009

Output

This project has the following output

Sentiment Score: 1.0%
Sentiment Type: Negative%
Very positive: 2.0%
Positive: 12.0%
Neutral: 25.0%
Negative: 52.0%
Very negative: 10.0%

sentiment-analysis's People

Contributors

ruthwik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.