Ex NO 9 DL LAB
Ex NO 9 DL LAB
To perform sentiment analysis on IMDb movie reviews using a Recurrent Neural Network
(RNN) model.
Procedure:
1. Load the IMDb movie reviews dataset and preprocess the text data.
2. Use an Embedding layer to convert input sequences into dense vectors of fixed size.
3. Add a SimpleRNN layer to process the embedded sequences.
4. Add a Dense layer with a sigmoid activation function for binary sentiment classification.
5. Compile the model using the Adam optimizer and binary crossentropy loss.
6. Use a TensorBoard callback to log metrics during training.
7. Train the model on the IMDb dataset.
8. Evaluate the model on the test set and print the accuracy.
9. Save the trained model for later use.
10. Plot the training and validation accuracy over epochs.
CODE:
import tensorflow as tf
from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, SimpleRNN, Dense
from tensorflow.keras.callbacks import TensorBoard
import datetime
import matplotlib.pyplot as plt