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
We'll use the Node.js library called vader.
npm i vader-sentiment
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);
Run the above code, you'll see output something like
{neg: 0.0, neu: 0.29, pos: 0.70, compound: 0.8545}
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)
You should try using pipedream.com to automate these types of workflows.