Book a free call

What Is Sentiment Analysis, and How Does It Work?

Sentiment analysis reads text and classifies the attitude behind it as positive, negative or neutral. Learn how it works, where it helps and where it fails.

Hertiv engineering teamReviewed by a senior engineer
6 min read
What Is Sentiment Analysis, and How Does It Work?
On this page

Short answer

Sentiment analysis is a natural language processing technique that reads text and classifies the attitude behind it, usually as positive, negative or neutral, sometimes with a score. Businesses use it to read reviews, support tickets and social posts at scale, but it works best on clear opinions and struggles with sarcasm, slang and mixed feelings.

What is sentiment analysis?

Sentiment analysis is a natural language processing technique that reads a piece of text and classifies the attitude behind it, usually as positive, negative or neutral, and sometimes with a score showing how strong the feeling is. A review that says 'delivery was fast and the product works well' is positive; one that says 'it broke after two days' is negative.

The point is scale. A person can read a hundred reviews in a day, but a business with ten thousand reviews a month cannot read them all. Sentiment analysis turns that pile of text into numbers a team can track: the share of positive reviews this week, the topics that draw complaints, or the change in tone after a product update.

It is sometimes called opinion mining, and it is one of the oldest applied uses of natural language processing. The output is a label or a score, never a full understanding of what the writer meant, which is why it works best as a triage tool rather than a final judgement.

How does sentiment analysis work?

Sentiment analysis works by breaking text into pieces, finding the words and phrases that carry attitude, and combining them into a label or a score. The pipeline usually has four steps: clean the text, split it into tokens, score the meaningful parts and aggregate the result into one label for the whole text.

Cleaning removes noise such as extra spaces, links and formatting. Tokenisation splits the text into words or parts of words. Scoring is where the approaches differ: a rule-based system looks words up in a list, a trained model predicts from examples it has seen, and a large language model reads the whole text in context.

Aggregation matters because a single text can hold several feelings. A review that praises the product but complains about delivery is positive about one thing and negative about another. Good systems report sentiment per aspect — product, price, delivery — instead of forcing one label on the whole review.

Sentiment analysis methods compared

Three approaches cover most real systems, and the right one depends on your data and your accuracy needs.

Method How it works Strength Weakness
Rule-based Word lists with positive and negative scores Fast, transparent, no training data Misses sarcasm and new slang
Machine learning Model trained on labelled examples Learns your domain's language Needs labelled data to train
LLM-based Large model reads text in context Handles nuance and mixed feelings Slower and more costly per text
Aspect-based Scores sentiment per topic in the text Shows what people like and dislike More complex to build and check

Most production systems combine approaches: a fast model handles the bulk of the text, and a larger model or a human reviews the cases the first model is unsure about. If you are scoping a first version, an AI proof of concept can compare two methods on your own data before you commit.

Where is sentiment analysis used?

Sentiment analysis is used wherever a business needs to read a large volume of opinion text and act on it. The most common uses are product reviews, support tickets, social media monitoring and employee feedback. In each case the goal is the same: find what people are happy or unhappy about, and find it early.

Support teams use it to prioritise tickets, routing angry or urgent messages to senior agents first. Product teams use it to track which features draw praise and which draw complaints after a release. Marketing teams use it to watch how a campaign or a crisis changes public tone over days rather than weeks.

It also appears in finance and research, where analysts track the tone of news and earnings calls, and in healthcare, where patient feedback is grouped by theme. The pattern is always the same: too much text for humans to read, and a decision that depends on the overall tone. See sentiment analysis use cases for more examples across industries.

Accuracy, limits and bias

Sentiment analysis is accurate on clear, simple opinions and unreliable on the rest. A short review that says 'great product' is easy to classify. Sarcasm, irony, slang, mixed feelings and domain-specific language all cause errors, and a model trained on movie reviews will misread medical or financial text.

Bias is a real problem. Models learn from the text they were trained on, so they can score some dialects, accents in written form or demographic groups differently from others. The fix is to test the system on your own data, split by the groups that matter to you, and check the error rate for each group rather than one overall number.

Treat the output as a signal, not a verdict. A sensible rule is to use sentiment scores for trends and triage, and to have a human read the individual texts that drive decisions about a customer, an employee or a public response. Never let a single score decide a refund, a hiring choice or a public statement.

Example: a shop measures review sentiment

Example (hypothetical): an online shop collects 1,000 product reviews in a month. A human reads a sample of 200 and labels 124 as positive, 48 as negative and 28 as neutral. The shop then runs a sentiment model over all 1,000 reviews.

The model labels 700 reviews as positive. Of those 700, 560 are truly positive when checked against human labels, so the precision is 560 divided by 700, which is 80%. The shop had 620 truly positive reviews in total, and the model found 560 of them, so the recall is 560 divided by 620, which is about 90%.

The team decides that 80% precision and 90% recall are good enough to track weekly trends and to flag negative reviews for a human to read, but not good enough to auto-reply to customers. That is the right use of the numbers: they describe what the system can be trusted to do, and the team acts within that limit.

What are the common mistakes?

The most common mistakes are trusting a single score, training on the wrong data and never checking the errors.

  • Trusting one overall score, when a review can be positive about the product and negative about delivery at the same time.
  • Training on generic data, then using the model on specialist text full of words the model has never seen.
  • Never reading the errors, so the same sarcasm or slang keeps fooling the system month after month.
  • Letting a score decide a customer outcome, such as an automatic refund or a public reply, without a human check.
  • Ignoring bias, and never testing whether the model scores some groups of writers differently from others.

If you want sentiment analysis built on your own data, our NLP development service covers data labelling, model choice and evaluation.

Key takeaways

  • Sentiment analysis classifies text as positive, negative or neutral, sometimes with a score
  • Rule-based systems are fast and transparent; trained models learn your domain; LLMs handle nuance
  • Aspect-based analysis shows what people like and dislike, not just the overall tone
  • Sarcasm, slang and mixed feelings are the main sources of error
  • Use scores for trends and triage, and let humans read the texts that drive decisions

Frequently asked questions

What is sentiment analysis in simple terms?

It is a technique that reads text and works out whether the writer feels positive, negative or neutral about something. A business uses it to read thousands of reviews, tickets or social posts and turn them into numbers it can track, such as the share of happy customers this week.

How accurate is sentiment analysis?

It is accurate on clear, simple opinions and much less reliable on sarcasm, irony, slang and mixed feelings. A model trained on one kind of text also performs worse on another kind. Always measure accuracy on your own data with precision and recall, not on a vendor's demo.

What is the difference between sentiment analysis and opinion mining?

They are the same thing in most usage. Opinion mining is the older term for extracting opinions from text, while sentiment analysis is the more common modern term. Both describe classifying the attitude in text, and the techniques and limits are identical.

Can sentiment analysis understand sarcasm?

Only partly. A sarcastic sentence often uses positive words to mean the opposite, which fools simple systems. Large language models do better because they read the whole sentence in context, but they still miss sarcasm often. Human review remains the reliable check for sarcastic text.

What data do I need to build sentiment analysis?

You need a sample of your own text with human labels showing the correct sentiment for each item. A few hundred labelled examples are enough for a first version, and more helps as you add aspects such as price or delivery. Clean, recent data from your own customers beats a large generic dataset.

Is sentiment analysis the same as emotion detection?

No. Sentiment analysis gives a broad label such as positive or negative, while emotion detection tries to name a specific feeling such as joy, anger or fear. Emotion detection is harder and less reliable, so most businesses start with sentiment and only add emotion labels when a use case clearly needs them.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Want sentiment analysis on your own customer feedback? Talk to Hertiv.

A senior engineer replies within one business day. Or see our NLP Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call