Sentiment, Opinion and Text Mining

Aspect-based sentiment analysis

Aspect-based sentiment analysis rates each part of a review separately, so one review can be positive about food and negative about service at once.

On this page 5
  1. Why it exists
  2. How it works
  3. Where you have already seen it
  4. Remember this
  5. What to learn next

One lesson, three depths. Pick the one that fits you today — you can switch any time.

Beginner — No maths. Plain English.

Aspect-based sentiment analysis rates each part of a review separately, instead of giving the whole thing one score.

Picture a restaurant review: "The food was fantastic, but the service was painfully slow." Is that a good review or a bad one? Both, depending on what you ask about.

A single overall sentiment score forces a choice that does not exist in the text. Aspect-based sentiment analysis avoids that. It rates the food positively and the service negatively, in the same review.

Why it exists

Plain sentiment analysis collapses everything into one number. That number hides useful detail the moment a review touches more than one topic.

A restaurant chain does not want to know "reviews are 70% positive." It wants to know food is loved and service is hated. That lets it fix the actual problem, instead of guessing.

Aspect-based sentiment splits a document by topic first, then scores each topic on its own. The result is a small table, not a single verdict.

How it works

Review: "Food is fantastic. Service was painfully slow. Prices are fair."
                            |
                            v
        Split by aspect: food, service, price
                            |
                            v
food     -> positive
service  -> negative
price    -> positive

The hard part is deciding which sentence belongs to which aspect before scoring anything. Get that step wrong, and even a perfect sentiment model scores the wrong topic.

Where you have already seen it

  • Google Maps and Zomato review summaries that break out "food," "service" and "ambience" separately. Direct aspect-based sentiment, shown to you as a table.
  • Amazon review highlights like "customers mention the battery life is poor." One specific aspect, pulled out and scored.
  • Hotel booking sites showing separate scores for cleanliness, location and staff. Each one scored from the same pool of reviews.
  • Product feedback dashboards used by companies internally. Tracking sentiment per feature, not one blended company-wide number.

Remember this

  • Aspect-based sentiment scores each topic in a document separately, not the whole document at once.
  • The same review can be positive about one aspect and negative about another.
  • Splitting text by aspect correctly matters as much as scoring sentiment correctly.

What to learn next

Developer — Code and libraries.

The simplest working approach: find sentences mentioning each aspect by keyword, then run sentiment analysis on each group separately.

Setup

bash
pip install transformers torch

Splitting one review into three aspects

absa.py
from transformers import pipeline

sentiment = pipeline("sentiment-analysis")   # distilbert, fine-tuned on SST-2

review = (
    "The food at this place is fantastic, easily the best biryani in the area. "
    "But the service was painfully slow, we waited forty minutes for our order. "
    "Prices are fair for the portion size though."
)

aspects = {
    "food": ["food", "biryani", "taste"],
    "service": ["service", "waited", "staff"],
    "price": ["price", "prices", "cost"],
}

sentences = [s.strip() for s in review.split(". ") if s.strip()]

for aspect, keywords in aspects.items():
    matches = [s for s in sentences if any(k in s.lower() for k in keywords)]
    if not matches:
        continue
    text = " ".join(matches)
    result = sentiment(text)[0]
    print(f"{aspect:8s} {result['label']:9s} ({result['score']:.3f})  {text}")
Output
food     POSITIVE  (1.000)  The food at this place is fantastic, easily the best biryani in the area
service  NEGATIVE  (0.999)  But the service was painfully slow, we waited forty minutes for our order
price    POSITIVE  (0.983)  Prices are fair for the portion size though.

Line by line

aspects is a plain keyword dictionary. This is the simplest possible way to route a sentence to a topic. It is not perfect: any sentence not containing one of these exact words gets missed entirely.

Each aspect gets scored independently. The food sentences and service sentences never influence each other's score. That is exactly the point: one bad sentence about service should not drag down the score for food.

All three scores landed correctly here, with high confidence. This is a genuinely easy example. Each sentence used an obvious, unambiguous keyword. Real reviews are messier, and this approach starts to strain quickly.

Common mistakes

Relying only on keyword matching for aspect detection. A sentence like "it took forever to arrive" is about service, to any reader. Yet it contains none of the listed service keywords. Production systems use a trained aspect-extraction model instead, not a fixed keyword list.

Splitting on ". " and calling it sentence segmentation. This breaks on abbreviations, decimals, and any sentence-ending punctuation other than a period-space. Use a real sentence tokenizer, like the one from splitting text into sentences, for anything beyond a quick demo.

Assuming every sentence has exactly one aspect. "The spicy chicken was great but overpriced" touches both food and price in one sentence. A keyword split either double-counts it or arbitrarily picks one.

Ignoring aspects the review never mentions. If a review never mentions "ambience," that is missing data, not a neutral or negative score. Do not silently fill in a default.

Try it yourself

Add the sentence "It took forever to arrive." to the review, without the word "service" or "waited" in it. Watch it get missed entirely by the current keyword list, and think about how you would catch it instead.

What to learn next

Researcher — Mathematics and papers.

The task, decomposed

Aspect-based sentiment analysis, ABSA, is usually decomposed into two or more subtasks, evaluated both separately and jointly:

Aspect term extraction (ATE). Identify the span of text naming an aspect, such as "battery life" or "service." This is typically framed as sequence labelling with BIO tags, the same machinery covered in BIO and BILOU tagging schemes.

Aspect category classification. Map a mention, or an entire sentence, onto a fixed set of predefined categories, such as food, service, price, ambience. This differs from ATE: a category can apply even when no specific span names it directly.

Aspect sentiment classification (ASC). Given an aspect, as a span or a category, predict its sentiment. It is conditioned specifically on that aspect, not the sentence as a whole.

The full pipeline task, End-to-End ABSA, performs all of these jointly. It is scored on the complete (aspect, sentiment) tuple extraction.

Why aspect-conditioned sentiment is harder than sentence-level sentiment

Standard sentiment classification asks P(sentiment | sentence). ASC instead asks P(sentiment | sentence, aspect), where the same sentence can produce different answers for different aspects. "The screen is great but the battery is a joke" requires selective attention. Positive when conditioned on "screen," negative when conditioned on "battery."

Architecturally, this means feeding the aspect term into the model alongside the sentence. A common format is [CLS] sentence [SEP] aspect [SEP]. A BERT-style encoder's attention can then condition on the aspect in question. It no longer produces one fixed embedding for every aspect.

Datasets

SemEval 2014-2016 Task 4 (Pontiki et al., 2014) established the standard ABSA benchmark. It covers restaurant and laptop reviews, annotated at the aspect-term and category level. Most subsequent ABSA research reports results on this benchmark family. Worth knowing, when reading papers that claim state-of-the-art results.

Joint modelling approaches

Early systems pipelined ATE, then ASC, as separate models, propagating extraction errors forward into sentiment scoring with no correction mechanism. Later work closes this gap by training extraction and sentiment jointly. Span-based joint models (Hu et al., 2019) do this. So do generative formulations that produce the full (aspect, opinion, sentiment) triple as text directly (Zhang et al., 2021). Sentiment signal then informs which spans are worth extracting.

Evaluation

ATE is scored with span-level F1, exact match against gold aspect boundaries. ASC is scored with accuracy or F1 over the sentiment labels, conditioned on gold aspects. This decouples sentiment scoring from extraction errors during evaluation, even though production systems face both at once.

Key references

  • Pontiki, M. et al. (2014). SemEval-2014 Task 4: Aspect Based Sentiment Analysis. SemEval.
  • Hu, M. et al. (2019). Open-Domain Targeted Sentiment Analysis via Span-Based Extraction and Classification. arXiv:1906.03820
  • Zhang, W. et al. (2021). Towards Generative Aspect-Based Sentiment Analysis. ACL.

Current state and open problems

LLMs can be prompted to extract and score aspects jointly as structured output. This now performs competitively with dedicated ABSA models on standard benchmarks, especially for common domains like restaurants and electronics.

The open problem is implicit aspects: sentiment expressed about a topic never named directly. "Arrived in two days, much faster than I expected" is about delivery speed, to any reader. The word "delivery" never appears at all. Keyword methods, and even most trained extraction methods, still miss this systematically. There is no explicit span to extract in the first place.

What to learn next