P

Sentiment Analysis: Definition and Examples

Sentiment analysis (or opinion mining) is a natural language processing (NLP) technique that automatically identifies and extracts opinions, emotions, and tones expressed in a text.

Full definition

Sentiment analysis, also called opinion mining, is a branch of natural language processing that aims to determine the emotional polarity of a text: positive, negative, or neutral. It relies on artificial intelligence models trained to recognize linguistic markers of emotion, judgment, and attitude in human language.

This technique goes far beyond simple binary classification. Modern sentiment analysis systems can detect subtle nuances such as irony, sarcasm, ambivalence, or mixed emotions. They are capable of analyzing sentiment at different levels of granularity: document level, sentence level, or even specific aspects of a product or service (aspect-based sentiment analysis).

In the context of prompt engineering, sentiment analysis is doubly relevant. On the one hand, large language models (LLMs) like Claude naturally excel at this task thanks to their deep understanding of language. On the other hand, understanding sentiment allows you to calibrate prompts to obtain responses adapted to the desired tone.

The applications are vast: brand reputation monitoring on social media, customer review analysis, detection of weak signals in user feedback, content moderation, or satisfaction analysis in customer support conversations. Companies heavily use this technology to transform large volumes of unstructured text data into actionable insights.

Etymology

The term combines 'sentiment' (from Latin sentimentum, meaning a feeling or opinion) and 'analysis' (from Greek analusis, meaning decomposition). The expression appeared in academic NLP literature in the early 2000s, notably with the pioneering work of Bo Pang and Lillian Lee on opinion classification in movie reviews (2002).

Concrete examples

Analysis of customer reviews for an e-commerce product

Analyze the sentiment of each customer review below. For each, indicate: polarity (positive/negative/neutral/mixed), confidence score (1-5), and specific aspects mentioned with their own sentiment.

Reviews:

  1. "The product is excellent but delivery took 3 weeks..."
  2. "Poor quality, I am very disappointed."
  3. "Okay for the price."

Brand monitoring on social media

You are a brand reputation analyst. Classify each tweet below according to the sentiment expressed towards our brand (positive, negative, neutral). For negative sentiments, identify the root cause of dissatisfaction. Format your response in a table with columns: Tweet | Sentiment | Cause (if negative) | Urgency (high/medium/low).

Analysis of verbatims from a satisfaction survey

Here are 50 open-ended responses from our satisfaction survey. Perform a grouped sentiment analysis: identify recurring themes, assign a dominant sentiment to each theme, and rank them by decreasing frequency. Conclude with the 3 priority actions to take.

Practical usage

In prompt engineering, sentiment analysis is used by explicitly asking the LLM to classify the tone and emotion of a text according to a defined scale (polarity, numerical score, emotion categories). For reliable results, provide clear classification criteria, ask for a justification for each evaluation, and specify the desired output format (table, JSON, summary). For large volumes, structure your prompt to process texts in batches with a consistent analysis grid.

Related concepts

Natural Language Processing (NLP)Text ClassificationOpinion MiningEmotion Detection

FAQ

What is the difference between sentiment analysis and emotion detection?
Sentiment analysis focuses on the general polarity of a text (positive, negative, neutral), while emotion detection identifies specific emotions such as joy, anger, sadness, surprise, or fear. Emotion detection is more granular and constitutes a finer subcategory of affective text analysis.
Are LLMs effective for sentiment analysis?
Yes, large language models like Claude are particularly effective for sentiment analysis, often without requiring specific training (zero-shot). Their contextual understanding of language allows them to handle sarcasm, double meanings, and cultural nuances better than traditional lexicon-based approaches. A well-structured prompt is usually sufficient to obtain high-quality results.
How to handle sarcasm and irony in sentiment analysis?
Sarcasm remains one of the major challenges of sentiment analysis because the literal meaning is opposite to the intended meaning. With an LLM, you can explicitly ask in your prompt to detect sarcasm before classifying the sentiment. Add an instruction like: 'First check if the text contains sarcasm or irony, and base your classification on the author's real intention, not the literal meaning.'

See also

How to use this prompt

  1. Copy the prompt with the button above.
  2. Paste it into ChatGPT, Claude or your favorite AI assistant.
  3. Replace the bracketed variables with your details, then refine the result.

About Prompt Guide

Prompt Guide is a free library of 2500+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.

More definitions

Get new prompts every week

Join our newsletter.