DEV Community

Cover image for Sentiment analysis using Node.js
Ishaan Sheikh
Ishaan Sheikh

Posted on

Sentiment analysis using Node.js

What is Sentiment analysis?

It refers to the use of natural language processing, text analysis, etc to identify or extract the emotional tone of the text. It is used by companies for classifying customer's reviews for products or movies as positive or negative and automating the process of handling spam etc.

Setting up an app

Initialize a Node.js app

npm init -y
Enter fullscreen mode Exit fullscreen mode

We'll use the Node.js library called vader.

npm i vader-sentiment
Enter fullscreen mode Exit fullscreen mode

Classifying text

// Require the library
const vader = require('vader-sentiment');

const input = 'The movie was awesome.';

const intensity = vader.SentimentIntensityAnalyzer.polarity_scores(input);
console.log(intensity);
Enter fullscreen mode Exit fullscreen mode

Run the above code, you'll see output something like

{neg: 0.0, neu: 0.29, pos: 0.70, compound: 0.8545}
Enter fullscreen mode Exit fullscreen mode

The compound score is computed by summing the valence scores of each word in the lexicon, adjusted according to the rules, and then normalized to be between -1 (most extreme negative) and +1 (most extreme positive).

Scoring

Positive Sentiment 👉 compound score >= 0.05
Neutral sentiment 👉 -0.05 < compound score < 0.05
Negative sentiment 👉 compound score <= -0.05

You can integrate this library into your app and can classify text without any machine learning.

Top comments (1)

Collapse
 
tod profile image
Tod Sacerdoti • Edited

You should try using pipedream.com to automate these types of workflows.