A product review analyser
The problem
Build a complete text classification pipeline in plain Python that labels product reviews as positive or negative, explains its decisions and measures how well it works.
Requirements
- Write or collect at least 60 short labelled reviews and split them into training and test sets
- Tokenize and normalize the text, keeping negations such as 'not'
- Build a lexicon baseline with negation and intensifier rules
- Train a multinomial Naive Bayes classifier with add-one smoothing on unigrams and bigrams
- Report accuracy and per-class precision, recall and F1 for both methods on the test set
- Print the most informative words for each class and the TF-IDF keywords of the misclassified reviews
Technologies
- Python
- Tokenization
- Naive Bayes
- TF-IDF
- Precision and recall
Step by step
- Write the reviews, label them, and set aside a fifth of them as the test set.
- Write the tokenizer and normalizer and test them on awkward examples.
- Implement the lexicon scorer and evaluate it on the test set.
- Train Naive Bayes on the training set and evaluate it on the same test set.
- Add bigram features and compare the results.
- Read every mistake and write down why the model failed.
Expected result
A working sentiment classifier with an evaluation report that compares rules with learning and explains the typical errors.
How it is evaluated
- Training and test data never mix
- Both methods are evaluated with the same metrics on the same test set
- Every function has a small test with a known answer
- The report explains at least three mistakes
Ways to improve it
- Replace Naive Bayes with logistic regression trained by gradient descent
- Use the average word embedding of each review as its features
- Compare with a pretrained transformer, such as Hugging Face's sentiment pipeline, on your own computer