https://github.com/zohaibramzan/sentiment_analysis_imdb_reviews
https://github.com/zohaibramzan/sentiment_analysis_imdb_reviews
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zohaibramzan/sentiment_analysis_imdb_reviews
- Owner: ZohaibRamzan
- Created: 2023-08-21T08:03:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T08:09:55.000Z (almost 2 years ago)
- Last Synced: 2025-01-12T15:08:31.050Z (5 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sentiment_Analysis_IMdb_Reviews
First Install the dependencies using 'pip install -r requirements.txt' then first do the training then test.
# Explanation:
This code performs sentiment analysis using the BERT (Bidirectional Encoder Representations from Transformers) model on the IMDb movie review dataset. The dataset is loaded using TensorFlow's Keras, consisting of movie reviews labeled as positive or negative. The reviews are preprocessed, padded or truncated to a fixed length, and converted into PyTorch tensors. A DataLoader is set up for batch training. The BERT pre-trained model and tokenizer are loaded from the 'bert-base-uncased' version. The optimizer (AdamW) and learning rate scheduler (linear schedule with warm-up) are configured. The training loop iterates through batches of data, moves them to the available device (GPU if available), computes the model's forward pass, calculates the loss, performs backpropagation, optimizer step, and updates the scheduler. Losses are stored and averaged for each epoch, and the loss per training step is plotted. Finally, the trained model and tokenizer are saved for later use in sentiment analysis tasks.