Skip to content
sentiment-analysis
Menu

Understanding the scores

This page explains the numbers in a Result and what changes them.

use Risan\Sentiment\Sentiment;

$result = Sentiment::analyze('VADER is smart, handsome, and funny.');

$result->compound; // 0.8316
$result->positive; // 0.746
$result->neutral;  // 0.254
$result->negative; // 0.0
$result->label;    // Label::Positive

Compound

compound is the one number to use when you want a single score. It runs from -1 (extremely negative) to +1 (extremely positive), with four decimals.

In the example, 0.8316 is close to +1. The text is clearly positive.

The package computes it in three steps:

  1. Each word in the lexicon adds its score (-4 to +4). The rules below adjust it.
  2. The package adds up the scores.
  3. It squashes the sum so it always lands between -1 and +1.

Because of the last step, a compound of 0.5 does not mean “50% positive”. Read it as a position on a scale. Near 0 is neutral. Near -1 or +1 is strong.

Positive, neutral and negative

These three numbers are shares of the weighted sentiment signal. Each is between 0 and 1, with three decimals. They add up to about 1.

In the example, 74.6% of the weighted sentiment signal is positive and none is negative. The other 25.4% is neutral. Words with no sentiment, such as VADER and is, count toward the neutral share. Strong words weigh more than mild words.

They are not probabilities. A text with many neutral words and one mild positive word has a high neutral and still a positive compound. To decide, use compound or the label. Use the three shares to see how a text is built.

Label

The Label comes from compound and the threshold:

Condition Label
compound >= threshold (and above 0) Label::Positive
compound <= -threshold (and below 0) Label::Negative
anything else Label::Neutral

The default threshold is 0.05. The VADER authors recommend this value.

What changes a score

The package does more than add up word scores. Here is how emphasis changes the compound score of the same word:

use Risan\Sentiment\Sentiment;

Sentiment::analyze('not good')->compound;     // -0.3412
Sentiment::analyze('good')->compound;         // 0.4404
Sentiment::analyze('very good')->compound;    // 0.4927
Sentiment::analyze('VERY good!!!')->compound; // 0.7005

These are the rules:

Rule Example Effect
Negation not good Flips the word and softens it
Intensifier very good, extremely bad Strengthens the word
Dampener kind of good, slightly bad Weakens the word
ALL CAPS this is GREAT Strengthens the shouted word
Exclamation marks great!!! Adds emphasis, up to 4 marks
Question marks great??? Adds a little emphasis
Contrast good food but terrible service The part after “but” weighs more
Emoticons and emoji :), ❤️, 😠 Count as sentiment words

Indonesian has the same rules. It adds intensifiers that come after the word (bagus banget), contrast words such as tapi and namun, and informal negations such as gak. See Languages.

Negation reaches three words back

A negation flips a sentiment word when it comes up to three words before it:

use Risan\Sentiment\Sentiment;

Sentiment::analyze('The food was not good.')->compound;
// -0.3412

Sentiment::analyze('The food was not at all good.')->compound;
// -0.3412

Sentiment::analyze('The food was not a thing that was good.')->compound;
// 0.4404

In the last text, not is five words away from good. It is too far to count, so good keeps its positive score.

Examples

TextLabelCompoundPosNeuNeg
This package is awesome!Englishpositive0.65880.5940.4060.000
The movie was good.Englishpositive0.44040.4920.5080.000
The movie was not good.Englishnegative-0.34120.0000.6240.376
It isn't bad at all.Englishpositive0.43100.4160.5840.000
The service was extremely good.Englishpositive0.49270.4440.5560.000
The service was kind of good.Englishpositive0.38320.3430.6570.000
The plot was good, but the ending was terrible.Englishnegative-0.49390.1490.5340.317
I LOVE this phone.Englishpositive0.71250.6220.3780.000
The concert was great!!!Englishpositive0.71630.6240.3760.000
Thanks for the help :)Englishpositive0.82250.8110.1890.000
Loved the show 😍Englishpositive0.78450.5800.4200.000
Worst day ever 😭Englishnegative-0.80200.0000.3570.643
The meeting is at 3 pm.Englishneutral0.00000.0001.0000.000
Filmnya bagus banget!Indonesianpositive0.62300.6710.3290.000
Makanannya enak sekali.Indonesianpositive0.58490.6550.3450.000
Pelayanannya tidak ramah.Indonesiannegative-0.35700.0000.4460.554
Tempatnya nyaman tapi harganya mahal.Indonesiannegative-0.12800.2670.4000.333
Aku BENCI antrean panjang!!!Indonesiannegative-0.68170.0000.3940.606
Hotelnya lumayan, tapi kamarnya kotor.Indonesiannegative-0.64280.1620.3240.514
Kamera hp ini keren parah 😍Indonesianpositive0.77780.4920.5080.000
Besok rapat jam 3 sore.Indonesianneutral0.00000.0001.0000.000

Tips

  • Use the label to classify. Use compound to rank.
  • Empty or whitespace-only text gives all zeros and a neutral label.
  • Text with no known words is neutral. The package only knows the words in its lexicon. Add your own words for slang from your field.
  • Long text works better one sentence at a time. See Long text.

Edit this page on GitHub