Skip to content

NLP (Concepts & Pipeline)

Sentiment Analysis

In shortNLP that detects whether text expresses a positive, negative or neutral opinion, often with a score for polarity and strength.

Updated 24 Oct 2026· 2 min read

Sentiment analysis is a natural language processing task that identifies the opinion or feeling expressed in text: whether the writer is positive, negative or neutral, and often how strongly. It is one of the most beginner-friendly NLP problems and one of the most useful for marketers, because so much customer feedback arrives as unstructured text.

How it works

There are four broad approaches, covered in MLforSEO’s sentiment deep dive:

  • Lexicon-based: words carry pre-assigned scores (“excellent” positive, “broken” negative) that are combined, with rules for negation and intensifiers. No training data needed.
  • Classic machine learning: models such as Naive Bayes, SVMs or logistic regression trained on labelled examples, often with TF-IDF features.
  • Deep learning: transformer models such as BERT variants fine-tuned for sentiment.
  • Generative AI: prompting an LLM to label sentiment, sometimes with explanations.

Cloud APIs package this up. The Google Cloud Natural Language API returns a score from -1.0 to 1.0 for polarity and a magnitude from 0 upwards for how much emotion is expressed, for the whole document and each sentence. IBM Watson NLU adds emotion scores such as joy, anger and fear. Entity sentiment analysis narrows it to specific things mentioned.

How it’s used in SEO and marketing

  • Analysing product and service reviews to find what customers love and dislike.
  • Monitoring brand mentions in social media, forums and the sources AI assistants cite.
  • Checking the tone of your own content, ad copy or competitor messaging.
  • Segmenting survey and support feedback for product and CX teams.
  • Comparing sentiment for your brand and competitors over time.

Example

MLforSEO’s Google Sheets tutorial runs a column of reviews through the Natural Language API with Apps Script and returns score and magnitude next to each one. A review scoring 0.1 with magnitude 3.5 is not neutral: it is mixed, with strong positive and negative statements cancelling out, and worth reading in full.

Limitations and things to watch

  • Sarcasm, irony, domain jargon and comparisons are still hard.
  • Different tools disagree. In an independent test cited in MLforSEO’s API comparison, three sentiment APIs each scored 67–72% accuracy on about 6,000 hand-labelled comments, but agreed with each other and with the human label on only 43.3% of items.
  • Overall scores hide mixed opinions; look at sentence or entity level.
  • Validate on a labelled sample from your own data before reporting results.

Learn it on MLforSEO

Where Sentiment Analysis shows up on MLforSEO

Sources and further reading

Other terms from NLP (Concepts & Pipeline)

See all 17 NLP (Concepts & Pipeline) terms →