Emerging Methods

Sentiment Analysis – Tools, Techniques and Examples

Table of Contents

Sentiment analysis is the computational process of identifying and classifying opinions, attitudes, or emotional tone in text. It commonly labels language as positive, negative, or neutral, but advanced methods can also detect intensity, specific emotions, opinion targets, and individual aspects of a product, policy, event, or experience.

Sentiment Analysis

Sentiment analysis helps researchers transform large collections of unstructured text into structured information. It can be applied to survey responses, interviews, social-media posts, news articles, product reviews, student feedback, political speeches, customer-support messages, and many other forms of written communication.

This article explains the meaning of sentiment analysis, how it works, its main types and methods, how researchers evaluate it, which tools are available, and which limitations must be considered before drawing conclusions.

Key Takeaways

  • Sentiment analysis uses computational methods to identify opinions, attitudes, polarity, or emotions in language.
  • A study may analyze sentiment at the document, sentence, target, or aspect level.
  • Common methods include sentiment lexicons, conventional machine learning, neural networks, transformers, large language models, and hybrid systems.
  • Accuracy alone is rarely sufficient; researchers should also examine precision, recall, macro-F1, confusion matrices, class balance, and human agreement.
  • Results depend heavily on language, domain, annotation rules, sampling, cultural context, and the definition of sentiment.
  • Automated predictions should be treated as measurements requiring validation, not as unquestionable evidence of what people truly feel.

What Is Sentiment Analysis?

Sentiment analysis, also known as opinion mining, is the computational study of opinions, evaluations, attitudes, emotions, and related subjective meanings expressed in language. It is usually treated as a branch of natural language processing, computational linguistics, text mining, and machine learning (Liu, 2020; Pang & Lee, 2008) [S1].

A basic sentiment-analysis system may classify text into three categories:

  • Positive: “The new search feature is fast and easy to use.”
  • Negative: “The update made the application unreliable.”
  • Neutral: “The update was released on Monday.”

More advanced systems may identify:

  • The intensity of an opinion.
  • The emotion being expressed.
  • The person or object being evaluated.
  • The particular feature being discussed.
  • Whether several conflicting opinions occur in the same text.
  • The author’s intention, such as complaining, requesting help, or recommending something.

Sentiment analysis does not directly observe a person’s private psychological state. It analyzes linguistic evidence and predicts a label or score according to a defined model. This distinction is important in academic research because written language may be strategic, humorous, indirect, culturally specific, or disconnected from the writer’s actual feelings.

Sentiment Analysis and Related Concepts

Sentiment analysis is often used interchangeably with several related terms, but the concepts are not identical.

ConceptMain questionExample output
Sentiment analysisIs the evaluation positive, negative, neutral, or mixed?Negative
Opinion miningWhat opinion is expressed, about what target, and by whom?Negative opinion about battery life
Emotion analysisWhich emotion is expressed?Anger or disappointment
Subjectivity analysisIs the statement subjective or factual?Subjective
Stance detectionIs the writer in favour of, against, or neutral toward a proposition?Against the policy
Intent classificationWhat is the writer trying to accomplish?Requesting a refund
Text analysisWhat broader patterns, topics, entities, or categories occur in text?Topic: delivery problems

Sentiment analysis vs. emotion analysis

Sentiment analysis generally measures evaluative direction, whereas emotion analysis identifies particular emotional categories or dimensions.

For example:

“I regret purchasing this laptop.”

A sentiment system might label the statement negative. An emotion-analysis system might label it sadness, disappointment, or regret.

Emotion classification is not simply a more detailed form of positive–negative classification. Anger and sadness may both be negative in valence, but they have different meanings, causes, and behavioural implications.

Sentiment analysis vs. stance detection

A person can express positive language while opposing a proposition, or negative language while supporting it.

“It is encouraging that the court finally rejected this harmful policy.”

The emotional tone surrounding the court’s action may be positive, but the stance toward the policy is negative. Researchers studying political communication should therefore avoid treating sentiment as a substitute for stance.

Sentiment analysis vs. satisfaction

Satisfaction is a specific evaluative construct. A customer can use positive words while reporting dissatisfaction, or use restrained language while reporting a serious problem. When satisfaction is the intended construct, researchers should validate whether sentiment labels correspond to independent satisfaction measures.

How Does Sentiment Analysis Work?

Sentiment analysis normally involves defining the task, collecting text, preparing and labelling the data, selecting a model, generating predictions, evaluating performance, and interpreting the results.

A defensible workflow contains the following steps.

1. Define the research question

The researcher must specify what will be measured.

Examples include:

  • What is the overall sentiment of student feedback?
  • Which aspects of online learning attract negative opinions?
  • How did public sentiment toward a policy change over time?
  • Does sentiment in financial reports relate to later market behaviour?
  • Which customer-service topics generate the strongest frustration?

A vague goal such as “analyze the comments” is insufficient. The unit of analysis, target, time period, population, language, and intended sentiment categories should be defined before model selection.

2. Collect the text

Potential sources include:

  • Open-ended survey responses.
  • Interview or focus-group transcripts.
  • Online reviews.
  • Social-media posts.
  • Discussion forums.
  • News reports.
  • Political speeches.
  • Earnings-call transcripts.
  • Customer-support tickets.
  • Emails or chat messages.
  • Student course evaluations.
  • Public consultation submissions.

Researchers must consider consent, platform terms, copyright, privacy, anonymization, and institutional ethics requirements. Public accessibility does not automatically remove all ethical responsibilities.

3. Determine the unit of analysis

A unit may be:

  • A whole document.
  • A review.
  • A paragraph.
  • A sentence.
  • A clause.
  • A social-media post.
  • A specified target or aspect.

The unit affects the meaning of the output. A long review containing praise and criticism may be labelled neutral or mixed at document level even though it contains highly informative aspect-level opinions.

4. Clean and prepare the text

Depending on the method, preparation may include:

  • Removing duplicates.
  • Correcting encoding problems.
  • Detecting language.
  • Separating sentences.
  • Tokenizing text.
  • Standardizing repeated spaces.
  • Handling URLs and user mentions.
  • Preserving or translating emojis.
  • Expanding contractions.
  • Lemmatizing words.
  • Removing irrelevant metadata.
  • Masking personal information.

Preprocessing should not be automatic or excessive. Negations, punctuation, capitalization, hashtags, emojis, and repeated letters can contain important sentiment information.

For example:

“GREAT service!!!”

Removing capitalization and punctuation may discard evidence of emphasis.

Similarly, removing a stop word such as “not” would reverse the meaning of:

“The service was not helpful.”

5. Create or select sentiment labels

A basic scheme may use:

  • Positive
  • Neutral
  • Negative

A fine-grained scheme may use:

  • Very positive
  • Positive
  • Neutral
  • Negative
  • Very negative

A project may also include:

  • Mixed
  • Unclear
  • Not applicable
  • No sentiment
  • Unable to determine

The labels should match the research question. Forcing all text into positive, neutral, or negative categories can create measurement error when the text is genuinely ambiguous, mixed, factual, or unrelated to the target.

6. Annotate a reference dataset

Supervised models require labelled examples. Even when a pretrained model is used, a manually labelled sample is needed to test whether the model works in the study’s actual domain.

A good annotation process includes:

  1. A written codebook.
  2. Definitions for each category.
  3. Examples and counterexamples.
  4. Instructions for mixed or unclear cases.
  5. More than one annotator for at least a subset.
  6. Training and pilot annotation.
  7. Documentation of disagreement.
  8. A justified adjudication procedure.

Inter-rater agreement can be assessed with measures such as percentage agreement, Cohen’s kappa, Krippendorff’s alpha, or another measure appropriate to the number of annotators and scale of measurement. Agreement statistics should be interpreted alongside the label distribution and difficulty of the task.

7. Apply the chosen method

The system may use:

  • A sentiment lexicon.
  • Manually constructed rules.
  • Logistic regression.
  • Naive Bayes.
  • Support vector machines.
  • Decision trees or ensemble models.
  • Convolutional or recurrent neural networks.
  • Transformer models such as BERT or RoBERTa.
  • A prompted or fine-tuned large language model.
  • A hybrid combination of methods.

8. Evaluate, inspect, and interpret the output

Researchers should compare predictions with human-labelled data, inspect common errors, test subgroup performance, and evaluate whether the model remains valid across languages, periods, platforms, and topics.

The final output may include:

  • Category frequencies.
  • Average sentiment scores.
  • Changes over time.
  • Aspect-specific sentiment.
  • Comparisons across groups.
  • Representative examples.
  • Uncertainty estimates.
  • Error categories.
  • Associations with other variables.

A Simple Sentiment-Analysis Example

Consider the review:

“The camera is excellent, but the battery drains quickly and customer support was unhelpful.”

A document-level classifier may label the complete review as negative, neutral, or mixed, depending on its scoring rules.

Aspect-based analysis provides more useful detail:

AspectOpinion expressionSentiment
Camera“excellent”Positive
Battery“drains quickly”Negative
Customer support“unhelpful”Negative

This example shows why the selected level of analysis matters. A single overall label can hide distinct opinions about different attributes.

Levels of Sentiment Analysis

Document-level sentiment analysis

Document-level analysis assigns one overall label or score to a complete document.

It works best when:

  • The document discusses one main target.
  • The opinion is relatively consistent.
  • The document is not excessively long.

It may be inappropriate when a document contains multiple subjects or conflicting opinions.

Sentence-level sentiment analysis

Sentence-level analysis classifies each sentence separately.

It can reveal changes in tone within a review, interview, speech, or article. However, sentences often depend on earlier context.

“I expected much better. It lasted only two days.”

The meaning of the second sentence depends partly on the first and on the object discussed previously.

Clause-level sentiment analysis

A sentence may contain more than one sentiment:

“The interface looks attractive, although navigation is confusing.”

Clause-level analysis separates the positive evaluation of appearance from the negative evaluation of navigation.

Target-level sentiment analysis

Target-level analysis identifies the sentiment directed toward a named entity or concept.

In the sentence:

“The lecturer was helpful, but the textbook was difficult to follow.”

The lecturer receives positive sentiment, while the textbook receives negative sentiment.

Aspect-based sentiment analysis

Aspect-based sentiment analysis identifies the sentiment associated with a specific characteristic, feature, or component of a target.

It may involve:

  1. Detecting the target or entity.
  2. Extracting its aspects.
  3. Identifying opinion expressions.
  4. Linking each opinion to the correct aspect.
  5. Assigning a sentiment label or score.

Because aspect extraction and opinion linking involve multiple decisions, aspect-based systems require more complex evaluation than ordinary document classification [S10].

Types of Sentiment Analysis

Binary sentiment analysis

Binary classification uses two labels, normally positive and negative.

It is simple to train and interpret, but it excludes neutral, mixed, and ambiguous cases. It is suitable only when the research question genuinely requires two classes.

Three-class sentiment analysis

The most familiar format classifies text as:

  • Positive
  • Neutral
  • Negative

The neutral category must be defined carefully. It may represent objective language, weak sentiment, balanced sentiment, absence of sentiment, or model uncertainty. These meanings should not be combined without justification.

Fine-grained sentiment analysis

Fine-grained analysis measures intensity, often with five categories ranging from very negative to very positive.

It may resemble a five-point rating scale, but predicted sentiment intensity should not automatically be treated as equivalent to a validated Likert-scale response.

Aspect-based sentiment analysis

Aspect-based analysis links sentiment to individual features or dimensions. It is especially useful for reviews, service evaluations, policy feedback, and educational comments.

Emotion analysis

Emotion models may classify language into categories such as:

  • Joy
  • Anger
  • Sadness
  • Fear
  • Surprise
  • Disgust
  • Trust
  • Anticipation

Other models represent emotion through continuous dimensions such as valence, arousal, and dominance.

Intent-based analysis

Intent analysis predicts why a person is communicating.

Possible intents include:

  • Complaining.
  • Requesting information.
  • Asking for technical support.
  • Recommending a product.
  • Threatening to cancel.
  • Reporting a safety issue.
  • Expressing praise.

Intent and sentiment can be combined, but they should remain conceptually distinct.

Multilingual sentiment analysis

Multilingual sentiment analysis processes more than one language or transfers a model trained in one language to another.

Challenges include:

  • Limited labelled datasets.
  • Dialect variation.
  • Translation artifacts.
  • Culture-specific expressions.
  • Different uses of politeness and indirectness.
  • Unequal model performance across languages.
  • Code-switching within the same sentence.

Multimodal sentiment analysis

Multimodal systems combine text with signals such as speech, facial expression, image, video, or conversational context.

These systems may provide richer evidence, but they introduce additional privacy, synchronization, modelling, and interpretation problems.

Main Sentiment-Analysis Approaches

Lexicon-based and rule-based methods

A sentiment lexicon is a dictionary in which words or phrases are associated with polarity or emotion scores.

A basic system might assign:

  • “Excellent” = positive
  • “Poor” = negative
  • “Acceptable” = mildly positive or neutral

Rules can adjust the scores for:

  • Negation.
  • Intensifiers.
  • Capitalization.
  • Punctuation.
  • Contrast words.
  • Emojis.
  • Repeated letters.

VADER is a well-known lexicon-and-rule-based approach designed for social-media-style text [S3].

Advantages

  • Transparent.
  • Fast.
  • Does not always require labelled training data.
  • Easy to inspect and modify.
  • Useful as a baseline.

Limitations

  • Vocabulary may not fit the domain.
  • Context and word sense can be missed.
  • Sarcasm and implicit sentiment remain difficult.
  • Performance may decline in other languages or disciplines.
  • Manually extending a lexicon can be labour-intensive.

The word “unpredictable,” for example, may be negative in a safety report but positive in a review praising an exciting film.

Traditional machine-learning methods

Conventional supervised learning converts text into numerical features and trains a classifier.

Common features include:

  • Word counts.
  • N-grams.
  • Term frequency–inverse document frequency.
  • Part-of-speech patterns.
  • Negation features.
  • Sentiment-lexicon scores.

Common classifiers include:

  • Logistic regression.
  • Naive Bayes.
  • Support vector machines.
  • Decision trees.
  • Random forests.

These methods remain useful because they are relatively efficient, interpretable, and competitive on well-defined datasets.

Their main limitation is their dependence on feature design and labelled examples. They may also fail when the language in the deployment data differs from the training data.

Deep-learning methods

Deep-learning systems learn representations from sequences of words or tokens.

Earlier approaches included:

  • Convolutional neural networks.
  • Recurrent neural networks.
  • Long short-term memory networks.
  • Gated recurrent units.
  • Recursive neural networks.

The Stanford Sentiment Treebank helped advance research into compositional sentiment and the way word combinations change meaning [S4].

Deep-learning models can capture more complex patterns than simple word-count systems, but they generally require greater computing resources, more training data, and more careful interpretation.

Transformer-based models

Transformer language models process words in relation to surrounding context. Models such as BERT can be fine-tuned for sentiment classification by adding a task-specific output layer [S5].

Transformers are often effective for:

  • Context-sensitive classification.
  • Transfer learning.
  • Multilingual analysis.
  • Fine-tuning with domain-specific data.
  • Target- and aspect-based tasks.

However, “transformer-based” does not guarantee validity. Performance still depends on the training corpus, labels, domain, language, time period, preprocessing, and evaluation design.

Large language models

Large language models can perform sentiment tasks through:

  • Zero-shot prompting.
  • Few-shot examples.
  • Structured-output instructions.
  • Fine-tuning.
  • Retrieval of domain definitions.
  • Multi-stage extraction and classification.

They are especially useful when labelled data are scarce or when a task requires flexible output. Nevertheless, research comparing LLMs across numerous sentiment tasks found that they performed satisfactorily on simpler classification tasks but could lag behind specialized models on more complex or structured sentiment tasks. They showed particular promise in few-shot settings [S6].

Hybrid methods

Hybrid systems combine two or more approaches.

Examples include:

  • Lexicon features plus logistic regression.
  • Rules plus a transformer classifier.
  • A specialist model followed by human verification.
  • An LLM that extracts aspects and a conventional classifier that assigns polarity.
  • An ensemble of several models.

Hybrid systems can improve robustness, but added complexity does not automatically improve validity. Each component and the combined system should be evaluated.

Comparison of Sentiment-Analysis Methods

ApproachLabelled data required?InterpretabilityComputational demandBest suited to
Lexicon/rule basedNot alwaysHighLowBaselines, transparent scoring, small projects
Traditional machine learningYesMedium to highLow to mediumWell-defined classification with labelled data
Deep neural networkUsuallyLowMedium to highLarger datasets and complex language patterns
Fine-tuned transformerYes, but transfer learning helpsLow to mediumMedium to highContext-sensitive and domain-specific classification
Prompted LLMNot necessarilyVariableMedium to highZero-shot, few-shot, exploratory, or flexible extraction
Hybrid systemDepends on componentsVariableVariableProjects requiring rules, adaptability, and human oversight

How to Conduct Sentiment Analysis in Academic Research

Step 1: Operationally define sentiment

State what sentiment means in the study.

For example:

Sentiment is defined as the evaluative polarity expressed toward the university’s online-learning services, classified as positive, neutral, negative, or mixed.

This definition is better than simply stating that a software package “detected emotions.”

Step 2: Define the target and unit

Identify:

  • Whose language is being analyzed.
  • The entity or issue being evaluated.
  • Whether the unit is a document, sentence, clause, or aspect.
  • Whether multiple opinions per unit are permitted.

Step 3: Develop the sampling strategy

Explain:

  • The population.
  • Source platform or corpus.
  • Date range.
  • Inclusion and exclusion criteria.
  • Search terms.
  • Language restrictions.
  • Handling of deleted, duplicated, automated, or reposted content.
  • Whether the sample represents the wider population.

Social-media users, online reviewers, and survey respondents are rarely random samples of an entire population.

Step 4: Prepare an annotation codebook

The codebook should include:

  • Category definitions.
  • Target definitions.
  • Examples.
  • Rules for negation and contrast.
  • Instructions for sarcasm.
  • Treatment of quotations.
  • Mixed-sentiment rules.
  • Treatment of factual statements.
  • Rules for emojis, abbreviations, slang, and code-switching.
  • A category for genuinely unclear material.

Step 5: Conduct pilot annotation

Annotators should independently label a pilot sample. Researchers can then identify unclear definitions and revise the codebook before completing the full annotation.

The pilot should not be used merely to force agreement. Disagreement may reveal genuine ambiguity in the construct or text.

Step 6: Select a baseline

A simple baseline makes model performance easier to interpret.

Possible baselines include:

  • Predicting the majority class.
  • A simple sentiment lexicon.
  • Logistic regression with TF-IDF features.
  • An existing pretrained classifier.

A complex model should demonstrate meaningful improvement over an appropriate baseline.

Step 7: Split the data correctly

For supervised learning, data are commonly divided into:

  • Training set.
  • Validation or development set.
  • Test set.

The final test set should not guide repeated model adjustment. Similar or duplicate texts should not appear across splits.

For temporal studies, training on earlier data and testing on later data may offer a more realistic assessment than a random split.

Step 8: Evaluate both quantitatively and qualitatively

Quantitative evaluation should be supplemented by manual error analysis.

Researchers should inspect errors involving:

  • Negation.
  • Sarcasm.
  • Multiple targets.
  • Mixed sentiment.
  • Domain terminology.
  • Dialect.
  • Quoted speech.
  • Comparisons.
  • Implicit evaluation.
  • Very short text.
  • Long contextual passages.

Step 9: Conduct subgroup and robustness checks

Where ethically and methodologically appropriate, compare performance across:

  • Languages.
  • Dialects.
  • Platforms.
  • Time periods.
  • Text lengths.
  • Topic categories.
  • Sentiment classes.
  • Demographic references.

A high overall score can hide poor performance for a smaller group or minority class.

Step 10: Preserve human oversight

Human review is especially important when sentiment predictions affect:

  • Healthcare decisions.
  • Employment.
  • Education.
  • Credit or insurance.
  • Public services.
  • Political profiling.
  • Safety escalation.
  • Individual-level interventions.

How Is Sentiment Analysis Evaluated?

Sentiment classification is normally evaluated by comparing model predictions with trusted reference labels.

Confusion matrix

A confusion matrix shows how often each true category is predicted as every possible category.

For positive, neutral, and negative classification, it can reveal whether:

  • Neutral text is frequently labelled positive.
  • Negative examples are overlooked.
  • One class dominates predictions.
  • The model struggles with adjacent categories.

Accuracy

Accuracy is the proportion of all predictions that are correct:

Accuracy = Correct predictions ÷ Total predictions

Accuracy is easy to understand, but it can be misleading when the classes are imbalanced.

Suppose 90% of comments are positive. A model that predicts “positive” for everything achieves 90% accuracy while failing to identify any negative or neutral comments.

Precision

Precision answers:

Of the items predicted as a class, how many actually belonged to that class?

Precision = True positives ÷ (True positives + False positives)

High precision is important when false alarms are costly.

Recall

Recall answers:

Of all items that truly belonged to a class, how many did the model identify?

Recall = True positives ÷ (True positives + False negatives)

High recall is important when missing relevant cases is costly.

F1 score

The F1 score is the harmonic mean of precision and recall [S9]:

F1 = 2 × (Precision × Recall) ÷ (Precision + Recall)

F1 is useful when both missed cases and false alarms matter.

Macro-F1

Macro-F1 calculates the F1 score for each class and then gives each class equal weight.

It is often more informative than accuracy for imbalanced positive, neutral, and negative datasets because performance on the largest class cannot completely dominate the result.

Weighted F1

Weighted F1 also calculates a score for each class but weights classes according to their frequency.

It summarizes overall performance but may conceal weak performance on rare classes. Reporting both macro and weighted results can therefore be useful.

Confidence and calibration

A model’s confidence score is not automatically a valid probability. A classifier that reports 0.90 confidence should ideally be correct approximately 90% of the time among comparable predictions.

Calibration matters when confidence thresholds determine whether a result is accepted automatically or referred for human review.

Inter-rater agreement

Human labels are not always an unquestionable ground truth. When annotators disagree substantially, low model performance may partly reflect an unclear task rather than only a poor algorithm.

Researchers should report:

  • Number of annotators.
  • Their training.
  • Agreement measure.
  • Adjudication procedure.
  • Whether the final test labels were independently established.

How Is a Sentiment Score Calculated?

There is no single universal formula for a sentiment score. Different lexicons, classifiers, APIs, and research projects use different scales.

A lexicon method may sum or average word scores. A machine-learning model may return class probabilities. A cloud API may provide proprietary polarity and magnitude measures. These scores should not be treated as interchangeable.

A commonly used descriptive measure is net sentiment:

Net sentiment = (Positive items − Negative items) ÷ Total classified items × 100

For example, if a dataset contains:

  • 600 positive comments
  • 250 negative comments
  • 150 neutral comments

Then:

Net sentiment = (600 − 250) ÷ 1,000 × 100 = 35

The interpretation depends on the defined denominator and treatment of neutral, mixed, duplicate, and unclassified items. Researchers should report the formula rather than presenting “sentiment score” as a standardized measure.

Applications of Sentiment Analysis in Modern Research

Education research

Researchers can analyze:

  • Course evaluations.
  • Student discussion forums.
  • Feedback on online learning.
  • Responses to teaching methods.
  • Institutional survey comments.
  • Public discussion of educational policy.

Sentiment results should not replace direct measures of learning, satisfaction, engagement, or educational quality.

Business and marketing research

Applications include:

  • Product-review analysis.
  • Brand monitoring.
  • Customer-service evaluation.
  • Competitor comparison.
  • Campaign response.
  • Employee feedback.
  • Product-feature assessment.

Aspect-level analysis is often more actionable than assigning one label to an entire review.

Political and public-opinion research

Researchers may examine:

  • Reactions to policies.
  • Election discourse.
  • Political speeches.
  • News comments.
  • Public consultations.
  • Protest communication.
  • Government-service feedback.

Sentiment is not equivalent to voting intention, ideology, agreement, or policy support. Stance detection and representative survey data may be needed.

Healthcare and public-health research

Potential applications include:

  • Patient feedback.
  • Public discussion of health services.
  • Medication experiences.
  • Health-campaign reactions.
  • Online support communities.
  • Public communication during emergencies.

Health-related language is sensitive and context-dependent. Automated labels should not be used to infer a diagnosis or mental state without appropriate clinical evidence and oversight.

Financial research

Sentiment analysis can be applied to:

  • News reports.
  • Earnings calls.
  • Annual reports.
  • Analyst commentary.
  • Investor forums.
  • Financial social media.

Financial meanings are highly domain-specific. A word such as “liability,” “volatile,” or “bearish” may require specialized training data and definitions.

Media and communication research

Researchers can study:

  • News framing.
  • Audience reactions.
  • Film and television reviews.
  • Online communities.
  • Crisis communication.
  • Public-relations campaigns.
  • Influencer communication.

Interpretation should account for quotation, reported speech, irony, platform culture, and communication goals.

Sentiment-Analysis Tools

VADER

VADER is a transparent lexicon-and-rule-based tool designed particularly for short, informal, social-media-style text [S3].

It is useful for:

  • Baseline models.
  • English social-media text.
  • Projects requiring quick, interpretable scores.
  • Teaching rule-based sentiment analysis.

It should still be validated on the target corpus.

NLTK

The Natural Language Toolkit provides corpora, tokenization, classification tools, and access to VADER.

It is useful for teaching and conventional NLP workflows, although researchers may need other libraries for modern transformer models.

TextBlob

TextBlob offers accessible polarity and subjectivity scores through a simple Python interface.

It is convenient for exploratory work but should not be used as an unquestioned measurement instrument. Its underlying assumptions may not suit specialized, multilingual, or contemporary social-media language.

Scikit-learn

Scikit-learn supports:

  • TF-IDF features.
  • Logistic regression.
  • Naive Bayes.
  • Support vector machines.
  • Train–test splitting.
  • Cross-validation.
  • Confusion matrices.
  • Precision, recall, and F1 metrics.

It is a strong choice for transparent baselines and traditional supervised models.

Hugging Face Transformers

Hugging Face provides access to pretrained transformer models and datasets. Researchers can use an existing sentiment pipeline or fine-tune a model for a particular language or domain [S12].

Model selection should consider:

  • Training language.
  • Original dataset.
  • Label definitions.
  • Domain.
  • License.
  • Maximum text length.
  • Model card limitations.
  • Evaluation results.

R tools

Researchers working in R may use packages such as:

  • tidytext
  • quanteda
  • text
  • sentimentr
  • Transformer interfaces through Python integration

The appropriate package depends on whether the study uses lexicons, statistical text analysis, or pretrained neural models.

Cloud APIs

Commercial cloud services can classify sentiment through APIs. Microsoft Azure Language can connect sentiment with particular text aspects, while Google Cloud Natural Language provides service-specific sentiment analysis and API outputs [S11].

Cloud services can reduce implementation effort, but researchers must consider:

  • Data-transfer and privacy rules.
  • Pricing.
  • Language availability.
  • Reproducibility.
  • Model-version changes.
  • Limited transparency.
  • Vendor-specific score definitions.
  • Whether data may leave the researcher’s institution or jurisdiction.

Large language model interfaces

General-purpose LLMs can classify text using prompts and structured formats. They are useful for pilots, schema development, few-shot classification, and difficult extraction tasks.

For reproducible research, document:

  • Model name and version.
  • Access date.
  • System and user prompts.
  • Temperature or randomness settings.
  • Examples included in the prompt.
  • Output format.
  • Retry procedure.
  • Human validation.
  • Cost and access conditions.

Advantages of Sentiment Analysis

Scalability

Automated methods can process volumes of text that would be difficult to code manually.

Consistency

A fixed model applies the same computational procedure to each input. This does not guarantee correctness, but it can reduce some forms of coder inconsistency.

Speed

Pretrained systems can provide rapid preliminary results and support near-real-time monitoring.

Fine-grained analysis

Aspect- and target-based methods can separate opinions about different features within the same text.

Integration with other methods

Sentiment labels can be combined with:

  • Topic modelling.
  • Thematic analysis.
  • Network analysis.
  • Time-series analysis.
  • Survey variables.
  • Experimental conditions.
  • Demographic variables.
  • Qualitative close reading.

Reproducibility

Open code, documented data, fixed model versions, annotation guidelines, and evaluation procedures can make computational analysis reproducible.

Limitations and Challenges

Sarcasm and irony

“Wonderful—another three-hour delay.”

The positive word “wonderful” expresses a negative evaluation. Correct interpretation may depend on world knowledge, punctuation, or context.

Negation

Compare:

  • “The service was helpful.”
  • “The service was not helpful.”
  • “The service was not entirely unhelpful.”

Negation scope can be difficult for both rule-based and learned models.

Mixed sentiment

“The research design is impressive, but the conclusions are overstated.”

A single label loses important information.

Implicit sentiment

“The battery lasted twenty minutes.”

No explicitly negative word appears, but the statement probably communicates criticism in most product-review contexts.

Domain dependence

“The plot was unpredictable.”

This may be positive for a thriller and negative for a scientific forecasting model.

Target ambiguity

“Unlike Company A, Company B finally listened to its users.”

The model must identify which organization receives which evaluation.

Quotation and reported speech

A news article may quote an angry statement without the journalist endorsing it. Document-level sentiment can therefore confuse the source’s tone with the quoted speaker’s attitude.

Cultural and linguistic variation

Politeness, indirect criticism, humour, emotional expression, and evaluative vocabulary differ across languages and communities. Directly translating an English lexicon or dataset may not preserve the same construct.

Dialect and demographic bias

Sentiment systems may produce systematically different predictions for text associated with particular demographic groups. A study of more than 200 systems found statistically significant gender- or race-related differences in some model outputs [S8].

Fairness testing should include counterfactual and subgroup evaluation where appropriate.

Annotation subjectivity

Two informed readers may reasonably disagree. Treating one label as the only possible truth can oversimplify ambiguous language.

Class imbalance

Neutral or positive examples may dominate a dataset. A model can appear accurate while performing poorly on important negative or minority cases.

Data leakage

Leakage occurs when information from the test data improperly influences training or model selection.

Examples include:

  • Duplicate reviews across train and test sets.
  • Multiple posts copied from the same source.
  • Selecting features using the full dataset.
  • Repeatedly tuning the model after examining test results.

Domain and temporal drift

Language changes over time. New slang, product names, political events, platform conventions, and meanings can reduce performance after deployment.

A model validated on older movie reviews may not work reliably on current healthcare discussions or code-mixed social-media posts.

Construct validity

A sentiment label may not measure what the researcher claims it measures.

Positive language is not automatically evidence of:

  • Satisfaction.
  • Agreement.
  • Trust.
  • Support.
  • Well-being.
  • Purchase intention.
  • Learning.
  • Service quality.

The link between the predicted label and the theoretical construct must be justified.

Privacy and ethical risk

Text may contain names, locations, health details, political opinions, or other sensitive information. Researchers should minimize data collection, secure the data, anonymize outputs, and consider whether individuals could be reidentified from quotations.

Sentiment Analysis Using AI and Large Language Models

Large language models have expanded the range of sentiment tasks that can be attempted without training a classifier from the beginning.

A prompt can request:

  • Polarity.
  • Intensity.
  • Emotion.
  • Target.
  • Aspect.
  • Opinion expression.
  • Explanation.
  • Structured JSON output.
  • Evidence spans.
  • Uncertainty or abstention.

Strengths of LLM-based analysis

  • Flexible zero-shot classification.
  • Few-shot adaptation through examples.
  • Ability to follow complex label definitions.
  • Extraction of targets and evidence.
  • Support for multiple languages.
  • Natural-language explanations.
  • Reduced need for a large labelled training set in early stages.

Limitations of LLM-based analysis

  • Outputs may vary between runs.
  • Model versions can change.
  • Explanations may sound convincing even when labels are wrong.
  • Proprietary systems may be difficult to reproduce.
  • Long-context processing can be expensive.
  • Sensitive data may be transmitted to an external provider.
  • Models may inherit cultural, linguistic, or demographic biases.
  • Complex aspect extraction may remain less reliable than simple polarity classification.
  • Prompts can unintentionally define the result.

A large 2024 evaluation across 13 sentiment tasks and 26 datasets found that LLMs performed satisfactorily on simpler tasks and strongly in few-shot settings, but were weaker on some complex tasks requiring structured sentiment information or deeper understanding of specific phenomena [S6].

The appropriate conclusion is not that LLMs have solved sentiment analysis, but that they provide an additional family of methods requiring task-specific validation.

Common Mistakes in Sentiment Analysis

Using a tool without local validation

A model’s published performance does not establish its accuracy on a new dataset.

Treating all neutral predictions as factual statements

Neutral may represent weak emotion, balanced opinion, uncertainty, or absence of recognizable sentiment.

Reporting only accuracy

Accuracy can conceal class imbalance and weak negative-class performance.

Removing meaningful language during cleaning

Deleting negations, punctuation, emojis, capitalization, or hashtags may remove sentiment signals.

Assuming a high confidence score means correctness

Confidence must be calibrated and tested.

Equating sentiment with the research construct

Sentiment should not be used as a proxy for satisfaction, support, health, or behaviour without evidence.

Ignoring mixed and aspect-level opinions

One overall label may erase the most useful information.

Translating text without validating the translation process

Translation can change intensity, politeness, idioms, and cultural meaning.

Using an LLM without recording the prompt and model

Unreported prompts and changing model versions make replication difficult.

Publishing identifiable text

Exact quotations can be searchable and may reveal the original writer even after usernames are removed.

How to Report a Sentiment-Analysis Study

A transparent methods section should report:

  1. Research question and definition of sentiment.
  2. Data source and sampling procedure.
  3. Collection dates.
  4. Inclusion and exclusion criteria.
  5. Languages and dialects represented.
  6. Unit and level of analysis.
  7. Label categories and codebook.
  8. Number and training of annotators.
  9. Inter-rater agreement.
  10. Preprocessing decisions.
  11. Model, lexicon, library, or API version.
  12. Training, validation, and test procedure.
  13. Hyperparameters or prompts.
  14. Baseline methods.
  15. Accuracy, precision, recall, F1, and class distribution.
  16. Confusion matrix and error analysis.
  17. Subgroup or robustness tests.
  18. Treatment of uncertain and mixed cases.
  19. Privacy and ethical safeguards.
  20. Limitations on generalization.
  21. Availability of code, prompts, data, or documentation.

Conclusion

Sentiment analysis is a family of computational methods for examining opinions, attitudes, evaluations, and affective meaning in language. Its value lies in making large text collections more manageable, but its outputs are only as credible as the research design behind them.

Researchers should define sentiment precisely, choose the correct level of analysis, validate the model on representative data, report class-specific performance, inspect errors, and account for language, culture, bias, privacy, and domain context. Automated sentiment labels should support interpretation—not replace methodological judgment or careful reading.

References

  • Das, A., & Zhang, W. E. (2020). ABSA-Bench: Towards the unified evaluation of aspect-based sentiment analysis research. In Proceedings of the 18th Annual Workshop of the Australasian Language Technology Association (pp. 65–71). Association for Computational Linguistics. https://aclanthology.org/2020.alta-1.7/
  • Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (pp. 4171–4186). Association for Computational Linguistics. https://doi.org/10.18653/v1/N19-1423
  • Google Cloud. (n.d.). Analyzing sentiment. Retrieved June 26, 2026, from https://cloud.google.com/natural-language/docs/analyzing-sentiment
  • Hutto, C. J., & Gilbert, E. (2014). VADER: A parsimonious rule-based model for sentiment analysis of social media text. Proceedings of the International AAAI Conference on Web and Social Media, 8(1), 216–225. https://doi.org/10.1609/icwsm.v8i1.14550
  • Kiritchenko, S., & Mohammad, S. M. (2018). Examining gender and race bias in two hundred sentiment analysis systems. In Proceedings of the Seventh Joint Conference on Lexical and Computational Semantics (pp. 43–53). Association for Computational Linguistics. https://doi.org/10.18653/v1/S18-2005
  • Lei, L., & Liu, D. (2021). Conducting sentiment analysis. Cambridge University Press.
  • Liu, B. (2020). Sentiment analysis: Mining opinions, sentiments, and emotions (2nd ed.). Cambridge University Press. https://doi.org/10.1017/9781108639286
  • Microsoft. (n.d.). What is sentiment analysis and opinion mining? Microsoft Learn. Retrieved June 26, 2026, from https://learn.microsoft.com/en-us/azure/ai-services/language-service/sentiment-opinion-mining/overview
  • Pang, B., & Lee, L. (2008). Opinion mining and sentiment analysis. Foundations and Trends in Information Retrieval, 2(1–2), 1–135. https://doi.org/10.1561/1500000011
  • Scikit-learn developers. (n.d.). F1 score. Retrieved June 26, 2026, from https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html
  • Socher, R., Perelygin, A., Wu, J., Chuang, J., Manning, C. D., Ng, A. Y., & Potts, C. (2013). Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing (pp. 1631–1642). Association for Computational Linguistics. https://aclanthology.org/D13-1170/
  • Venkit, P. N., Srinath, M., Gautam, S., Venkatraman, S., Gupta, V., Passonneau, R. J., & Wilson, S. (2023). The sentiment problem: A critical survey towards deconstructing sentiment analysis. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing (pp. 13743–13763). Association for Computational Linguistics. https://doi.org/10.18653/v1/2023.emnlp-main.848
  • Zhang, W., Deng, Y., Liu, B., Pan, S., & Bing, L. (2024). Sentiment analysis in the era of large language models: A reality check. In Findings of the Association for Computational Linguistics: NAACL 2024 (pp. 3881–3906). Association for Computational Linguistics. https://doi.org/10.18653/v1/2024.findings-naacl.246

About the author

Muhammad Hassan

Muhammad Hassan writes about research design, academic methods and data-analysis concepts for ResearchMethod.net. His work focuses on presenting methodological topics in clear language for students and early-career researchers. Articles are developed from recognized methodological literature and official software documentation.