Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 3 — Sentiment Analysis: Approaches & Techniques

Lesson 28 of 39 in the free Natural Language Processing notes on Siksha Sarovar, written by Rohit Jangra.

Sentiment Analysis — Approaches & Techniques

Sentiment analysis (opinion mining) determines the emotional tone/polarity of a piece of text — typically positive, negative, or neutral — and is one of the most widely deployed real-world NLP applications (product reviews, social media monitoring, brand tracking).

Levels of Sentiment Analysis

LevelGranularityExample
Document-levelOne sentiment for the whole documentOverall review sentiment
Sentence-levelOne sentiment per sentence"Battery is great. Camera is disappointing." → 2 different sentiments
Aspect-based (ABSA)Sentiment per specific attribute/feature"Camera: negative, Battery: positive" for the same review

Approach 1 — Lexicon-Based (Rule-Based)

Uses a pre-built dictionary of words tagged with sentiment scores (e.g. "excellent" = +3, "terrible" = -3), then sums/averages scores across the text.

"The battery life is excellent but the camera is terrible"
   excellent (+3)                        terrible (-3)
Overall score: +3 + (-3) = 0  -> roughly neutral/mixed

Handling negation is critical for lexicon methods (recall Unit 1's stop-word caveat about "not"):

"not good"  -> naive lexicon sees "good" (+2) and ignores "not" -> WRONG (+2)
"not good"  -> negation-aware: flip sign of following sentiment word -> CORRECT (-2)

Approach 2 — Machine Learning-Based (Supervised)

Treats sentiment analysis as text classification (exactly the Naïve Bayes pipeline from the previous lesson) — train on labeled examples (review text → positive/negative label), extract TF-IDF features, and classify.

Approach 3 — Deep Learning / Transformer-Based (Preview of Unit 4)

Modern systems use contextual embeddings (BERT-style models) fine-tuned on sentiment-labeled data, which handle negation, sarcasm, and context far better than lexicon or bag-of-words approaches, since the representation of each word already depends on its surrounding sentence.

Comparing the Three Approaches

ApproachNeeds labeled data?Handles negation/contextSpeed
Lexicon-basedNoPoor (unless rule-augmented)Very fast
ML-based (Naïve Bayes/SVM + TF-IDF)YesModerate (bigrams help a bit)Fast
Deep learning / TransformerYes (often large datasets)ExcellentSlower, needs more compute

Challenges Specific to Sentiment Analysis

  1. Negation: "not bad" is actually mildly positive, not negative.
  2. Sarcasm/irony: "Oh fantastic, my flight got delayed again" — positive words, negative sentiment.
  3. Comparative sentences: "Phone A is better than Phone B" — sentiment is relative, not absolute.
  4. Domain dependence: "unpredictable" is negative for a car ("unpredictable brakes") but positive for a movie plot ("unpredictable twist").
  5. Mixed/aspect-level sentiment: a review can be positive about one aspect and negative about another simultaneously.

We build a hands-on sentiment classifier — both lexicon-based and ML-based — in the next lesson.