Oct 2023 · Dec 2023
Sentiment Analysis for Movie Reviews
An embedding-based classifier reaching 89% accuracy on IMDb reviews.
- Python
- TensorFlow
- Keras
- NLP
- Test accuracy
- 89%
- Vocabulary size
- 88k
A neural network that classifies IMDb movie reviews as positive or negative, built to understand how text becomes something a network can consume.
Preprocessing
Raw review text is encoded into integers using a custom dictionary and padded to a uniform length, with the vocabulary filtered to the 88,000 most common words. Padding and truncation choices matter more than they appear to: they decide how much of a long review the model actually sees.
Architecture
An embedding layer maps words into 16-dimensional vectors, a GlobalAveragePooling1D layer reduces
dimensionality, and dense layers with ReLU and sigmoid activations produce the binary classification.
Averaging pooled embeddings is a deliberately simple approach: it discards word order entirely, and it
still reaches 89% accuracy, which is a useful lesson about baselines.
Inference
The trained model is saved and reloaded by a separate script that scores new reviews read from an external text file, so it works on text it has never seen rather than only on a held-out split.