Sentiment analysis

Sentiment Analysis Lab

Analyze sentiment with an Arabic and English lexicon, handling negation and intensifiers, and see which words drive the result for each sentence.

What is this module?

Sentiment Analysis classifies text as positive, negative or neutral. Lexicon-based analysis sums the polarity values of words from a lexicon and adjusts them with rules for negation, intensifiers and contrastive particles. Trained models (Naive Bayes, SVM, then transformer models such as MARBERT and CAMeLBERT fine-tuned on sentiment data) learn from labeled examples and capture context better, but they need data and training and are affected by the text's domain and dialect.

Tool: Sentiment analysis

Runs in your browser (JavaScript) — your text is not sent anywhere
Settings

How does the tool work?

  • Each word is matched against the lexicon (after normalization and clitic separation) and gets a value between −3 and +3.
  • A negation word up to three words before the word flips the sign.
  • An intensifier immediately before or after multiplies the value by 1.5.
  • Whatever follows «لكن» and "but" has its weight doubled.
  • Verdict: a total above +0.5 is positive, below −0.5 is negative, and anything in between is neutral.

How to read the results?

The table shows the influential words, their final weight and the reason it was adjusted. "Coverage" is the share of words found in the lexicon: if it is low, the verdict has low confidence.

Algorithms and methods

We always distinguish between traditional algorithms, resource-based methods and trained models. The tools on this page are traditional or lexicon-based, while trained models are explained here and run only through an external engine enabled by the site admin.

Limitations and accuracy limits

Lexicon-based analysis does not understand sarcasm, compound negation, figurative meaning or wider context, and the lab lexicon is limited and made for teaching. Do not use its results in research decisions without a trained model and an evaluation.

This tool's results are educational: they show how the algorithm works step by step, and they are not presented as confirmed scientific results.

From the knowledge base

Reading the results

How to read the sentiment result

The score is the sum of the weights of the known words after negation and intensification. Look at the "coverage": if few words are known, the result means little. Read the result of each sentence, because the total may hide opposite sentences.

Lab documentation

Concept

Levels of sentiment analysis

Opinion is analysed at the level of the document, the sentence or the aspect. The finer the required detail, the finer the data labelling must be. Methods: lexicon-based, traditional machine learning on features such as TF-IDF, and pretrained models.

Liu (2012) Sentiment Analysis and Opinion Mining

Frequently asked questions

What is sentiment analysis?

Determining the direction of the opinion in a text: positive, negative or neutral, and sometimes its strength or topic. It is used to analyse customer opinions and social media.

How does the lab compute sentiment?

With a lexicon method: it looks for words that are in a sentiment lexicon, each with a weight from -3 to +3, flips the sign if a negation particle precedes the word, multiplies it by 1.5 if an intensifier such as «جداً» or «كلش» is next to it, and doubles the weight of what comes after «لكن» or «بس» ("but"). Then it adds up the weights for each sentence: above +0.5 is positive, below −0.5 is negative, and in between is neutral.

Why does lexical analysis fail with sarcasm?

Because sarcasm uses positive words with a negative meaning, such as «ما أروع الزحام اليوم!» ("How wonderful the traffic is today!"). The lexicon only sees «أروع». Detecting sarcasm needs context and trained models, and even these often get it wrong.

Where did the lab's sentiment lexicon come from?

It is a small teaching lexicon written for this lab, not copied from published lexicons with restrictive licence terms. Its weights are estimates for teaching, and an administrator can edit them or import a licensed lexicon.

What is the difference between sentence-level and text-level sentiment?

Sentence analysis gives a verdict for each sentence, and text analysis combines them. A text may contain positive and negative sentences, so the total appears neutral even though a strong opinion is present. That is why the lab shows both results.

Does the lab understand sentiment in the dialects?

Partly. The lexicon includes some common dialect words (such as حلو, زين, خوش, كلش and وايد), but coverage is limited. Results on dialect text are estimates.

Which negation particles does the lab know?

In MSA: لا, لم, لن, ليس, ما, غير, بدون. In the dialects: مو, مش, ماكو, موش, مهوش, ماشي. They flip the effect of the next word within a short window.

What are the well-known trained models for Arabic sentiment?

There are models fine-tuned from MARBERT, CAMeLBERT and AraBERT on datasets such as ASTD, ArSAS and LABR. Check the licence of each model and dataset before use, since some are for research only.

Why does the result change if I remove stopwords first?

Because some stopwords are negation or intensifying particles. Removing them makes «لا أحب» ("I don't like") look like «أحب» ("I like"). That is why the lab keeps negation particles by default.

What does "neutral" mean in the result?

That the sum of the weights is close to zero within a set threshold, or that the text contains no words from the lexicon. The second case is shown with the phrase "No known sentiment words" so it is not taken as genuine neutrality.

Does the lab analyse aspect-based sentiment?

No. Aspect-based sentiment analysis, as in «الكاميرا ممتازة لكن البطارية سيئة» ("the camera is excellent but the battery is bad"), needs a model that identifies the aspects. The lab works at the sentence level, and shows a sentence as mixed if it contains both positive and negative words.

What is the right evaluation metric for sentiment with imbalanced classes?

Macro-F1 or the F1 of the minority class is preferred, because overall accuracy is misleading when one class dominates.

Exercises and challenges

Beginner Hands-on in the lab

Positive or negative

Analyse the "A positive opinion" and "A negative opinion" examples. Which words decided the result?

Hint

Look at the coloured words.

Show solution

In the positive one: ممتازة, لطفاء, رائعة, أنصح. In the negative one: بطيء, أخطاء, سيئة, مخيبة.

Beginner Computing by hand

Computing by hand

With the weights ممتاز = +3, سيء = −2, جميل = +2, and negation flipping the sign, compute the total for «الطعام ممتاز لكن المكان ليس جميلاً والخدمة سيئة».

Hint

«ليس جميلاً» = −2.

Show solution

+3 − 2 − 2 = −1, that is, weakly negative.

Intermediate Hands-on in the lab

Intensifiers

Compare «الأكل طيب», «الأكل كلش طيب» and «الأكل طيب جداً». How does the score change?

Hint

An intensifier multiplies the weight of the neighbouring word by 1.5.

Show solution

The score rises with «كلش» and «جداً» because they are known intensifiers in the lexicon.

Intermediate Conceptual question

Sarcasm

Why does lexical analysis get the "Sarcasm" example wrong? Suggest a better method.

Hint

The meaning is the opposite of the words.

Show solution

Because the lexicon only sees «رائع». A model trained on data containing sarcasm is better, such as models fine-tuned on the ArSarcasm dataset, keeping in mind that accuracy remains limited.

Advanced Computing by hand

Macro-F1

A sentiment classifier has F1 = 0.90 for positive, 0.40 for negative and 0.70 for neutral. What is the Macro-F1? And why might overall accuracy be misleading here?

Hint

The arithmetic mean.

Show solution

Macro-F1 = (0.90+0.40+0.70)/3 ≈ 0.667. Overall accuracy may be high if most examples are positive, hiding the weakness of the negative class.

Intermediate Hands-on in the lab

Iraqi dialect

Analyse «الأكل كلش طيب والمكان خوش، بس الخدمة مو زينة». Did the tool catch the negation «مو»?

Hint

Look at the second clause.

Show solution

Yes, «مو زينة» flips «زين» to negative. The overall result is approximate because the dialect lexicon is limited.

Advanced Research challenge

An Arabic sentiment lexicon

Find two published Arabic sentiment lexicons, and compare how they were built and their licences.

Hint

ArSenL and others.

Show solution

Examples include ArSenL, built by linking SentiWordNet to an Arabic dictionary. Check the licence and terms of use before importing any lexicon.

Related sections of the site