Guided project · NLP
Build a sentiment analyser for product reviews
Build a classic NLP model that reads reviews and decides if they're positive or negative, then compare it with an LLM.
What you'll build
A working sentiment classifier you can test with your own sentences, and a comparison with a chatbot.
What you'll learn
- Turning text into numbers (bag of words)
- Training Naive Bayes and logistic regression
- Where simple models fail (negation, sarcasm)
You'll need
Google Colab (free) and any AI chatbot
Create a free account to unlock this project
The step-by-step instructions, copy-ready prompts, progress tracker and portfolio texts are for members. It's free, takes under a minute, and unlocks all guided projects.
Want to try first? These projects are open to everyone: Prompt lab and One idea, five posts.
Before you start
- Open a new notebook at colab.research.google.com.
Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.
Step by step
Write a small labelled dataset
Run this cell. It holds 24 short reviews labelled 1 (positive) or 0 (negative).
Copy this codereviews = [ ('love it, works perfectly', 1), ('great quality and fast delivery', 1), ('excellent value, very happy', 1), ('really good, would buy again', 1), ('amazing sound and easy to use', 1), ('fantastic, my kids love it', 1), ('works great and looks nice', 1), ('very comfortable and well made', 1), ('happy with this purchase', 1), ('superb battery life', 1), ('best phone case I have owned', 1), ('good product for the price', 1), ('broke after two days', 0), ('terrible quality, waste of money', 0), ('stopped working, very disappointed', 0), ('poor fit and cheap material', 0), ('awful customer service', 0), ('arrived damaged and late', 0), ('does not work as described', 0), ('the worst purchase this year', 0), ('battery dies quickly, bad', 0), ('uncomfortable and too small', 0), ('cheap and flimsy, returned it', 0), ('not worth the money', 0), ] texts = [t for t, _ in reviews]; labels = [l for _, l in reviews] print(len(texts))You should see: The number 24.
Turn words into numbers
Count the words in each review (a bag of words).
Copy this codefrom sklearn.feature_extraction.text import CountVectorizer vec = CountVectorizer() X = vec.fit_transform(texts) print(vec.get_feature_names_out()[:30])You should see: A list of the vocabulary the model will use.
Why it matters: Computers can't read words, so every review becomes a row of word counts.
Train Naive Bayes
Train the model on all 24 reviews.
Copy this codefrom sklearn.naive_bayes import MultinomialNB nb = MultinomialNB().fit(X, labels)You should see: No output yet; the model is trained.
Test it with your own sentences
Edit the sentences and run again as many times as you like.
Copy this codetests = ['very good quality', 'it broke, so disappointed', 'not bad at all', 'oh great, it stopped working again'] for t, p in zip(tests, nb.predict(vec.transform(tests))): print(p, t)You should see: 1 for positive and 0 for negative next to each sentence. Simple ones are usually right.
See which words matter
List the words most linked to positive and to negative.
Copy this codeimport numpy as np words = vec.get_feature_names_out() score = nb.feature_log_prob_[1] - nb.feature_log_prob_[0] print('positive:', words[np.argsort(score)[-8:]]) print('negative:', words[np.argsort(score)[:8]])You should see: Words like great and love on one side, broke and waste on the other.
Try logistic regression
Train a second model and test the same sentences.
Copy this codefrom sklearn.linear_model import LogisticRegression lr = LogisticRegression().fit(X, labels) for t, p in zip(tests, lr.predict(vec.transform(tests))): print(p, t)You should see: Similar results; both struggle with "not bad" and sarcasm.
Compare with an LLM
This step happens outside Colab. Open a new browser tab and go to any AI chatbot, for example ChatGPT, Claude or Gemini. Click Copy below, paste the text into the chat box and press Enter. Then compare its four answers with the 1s and 0s your Colab models printed in steps 4 and 6 (1 = positive, 0 = negative).
Copy this textClassify each review as positive or negative and explain in 5 words why: 1. very good quality 2. it broke, so disappointed 3. not bad at all 4. oh great, it stopped working againYou should see: The LLM usually gets all four right: 1 positive, 2 negative, 3 positive ("not bad" is praise) and 4 negative (it's sarcasm). Your small models often get 3 or 4 wrong, because they only count words: "bad" looks negative and "great" looks positive.
Write your conclusion
Back in Colab, click + Text to add a text cell. Make a small table of the 4 sentences with three columns: Naive Bayes, logistic regression and LLM. Then write two lines: when you'd use a small model (cheap, fast, private) and when an LLM (better understanding).
You should see: A clear, practical comparison you can explain in an interview.
Brilliant work. Share it below, then pick your next project.
Level up
- Add 20 more reviews and see if the hard cases improve.
- Use CountVectorizer(ngram_range=(1, 2)) so it sees word pairs like "not bad".
Lessons behind this project
Show it off
Finished? Post about it on LinkedIn. Here's a starting point; add a screenshot and your own words.
I built a sentiment analyser with Naive Bayes, then compared it with an LLM on tricky reviews like "not bad at all". Word counts vs real understanding! Learned with AI From Zero.Add it to your portfolio
Employers love seeing what you've built. Use these ready-made texts, then add your own results and a screenshot.
1. A line for your CV or LinkedIn "Projects" section
Build a sentiment analyser for product reviews: A working sentiment classifier you can test with your own sentences, and a comparison with a chatbot. Skills: Turning text into numbers (bag of words), Training Naive Bayes and logistic regression, Where simple models fail (negation, sarcasm). Tools: Google Colab (free) and any AI chatbot.2. A README for GitHub
Create a free GitHub account, make a new repository, add a file called README.md and paste this in along with your notebook (File → Download → .ipynb).
# Build a sentiment analyser for product reviews
Build a classic NLP model that reads reviews and decides if they're positive or negative, then compare it with an LLM.
## What I built
A working sentiment classifier you can test with your own sentences, and a comparison with a chatbot.
## What I learned
- Turning text into numbers (bag of words)
- Training Naive Bayes and logistic regression
- Where simple models fail (negation, sarcasm)
## Tools
Google Colab (free) and any AI chatbot
## How it works
1. Write a small labelled dataset
2. Turn words into numbers
3. Train Naive Bayes
4. Test it with your own sentences
5. See which words matter
6. Try logistic regression
7. Compare with an LLM
8. Write your conclusion
## Results
(Add a screenshot and 2–3 sentences about what you found. Never include API keys or personal data.)
## Next steps
- Add 20 more reviews and see if the hard cases improve.
- Use CountVectorizer(ngram_range=(1, 2)) so it sees word pairs like "not bad".
---
Built by following the free guided project at https://learnaifromzero.com/projects/sentiment-analyser.html