A recurrent neural network built with PyTorch to classify IMDB movie reviews as positive or negative.
This project implements a text preprocessing pipeline and an RNN from scratch to perform binary sentiment classification on the IMDB Dataset of 50,000 movie reviews.
- IMDB Dataset of 50K Movie Reviews
- 49,582 reviews after removing duplicates (25k+ positive, 25k+ negative)
- Labels encoded via
LabelEncoder(positive = 1, negative = 0)
- Lowercasing
- URL removal
- Punctuation removal
- HTML tag removal
- Stopword removal (NLTK)
- Stemming (Porter Stemmer)
- Vectorization via TF-IDF (
TfidfVectorizer, max 5000 features)
- Single-layer RNN (
nn.RNN), hidden size 128 - Fully connected output layer (128 → 1)
- Sigmoid activation for binary classification
- Loss function: Binary Cross-Entropy Loss
- Optimizer: Adam
- Epochs: 10
- Batch size: 64
- Test accuracy: 85.61%
torch
scikit-learn
nltk
pandas
python train.pyTrains the RNN on the preprocessed reviews and evaluates accuracy on the held-out test set.
Samir B K GitHub: github.com/Samir-BK