This project implements a binary sentiment classification model using TensorFlow and TensorFlow Hub.
The model is trained on the IMDB movie reviews dataset and predicts whether a review is positive or negative.
Natural Language Processing (NLP) techniques are used to convert text into embeddings before feeding them into a neural network classifier.
The project uses the IMDB Reviews dataset provided by TensorFlow Datasets.
Dataset characteristics:
- 50,000 movie reviews
- Binary sentiment labels
- Balanced dataset
The dataset is automatically downloaded using tensorflow_datasets.
The model consists of:
-
Input Layer
- Accepts raw text input
-
Embedding Layer
- Pretrained text embedding from TensorFlow Hub
- Converts text into numerical vectors
-
Dense Hidden Layer
- 16 neurons with ReLU activation
-
Output Layer
- Sigmoid activation for binary classification
- Python
- TensorFlow
- TensorFlow Hub
- TensorFlow Datasets
- NumPy
Create a virtual environment:
python -m venv .venvActivate it:
Windows:
.venv\Scripts\activateInstall dependencies:
pip install tensorflow tensorflow-hub tensorflow-datasetsRun the training script:
python main.pyThe script will:
- Download the IMDB dataset
- Preprocess the text data
- Train a neural network classifier
- Evaluate model performance
The model will output metrics such as:
Epoch 1/5
accuracy: 0.84
val_accuracy: 0.86
Future improvements could include:
- Using advanced models such as BERT
- Adding dropout layers for regularization
- Hyperparameter tuning
- Saving and exporting the trained model
- Deploying the model as an API
Arul Gupta BITS Goa – Electronics and Communication Engineering