Deep DL Manual Nainish
Deep DL Manual Nainish
PRACTICAL-6
Deep Learning Library and Write a Code for Encoding
With (One_Hot).
IMPLEMENTATION:
OUTPUT:
PRACTICAL-7
deep learning library and write a code for Hash
Encoding with (hashing_trick).
IMPLEMENTATION:
OUTPUT:
PRACTICAL-8
deep learning library give a demo of Tokenizer API.
IMPLEMENTATION:
output:
PRACTICAL-9
AIM:Experiment to do Sentimental Analysis on any of the Dataset (like twitter
tweets, movie review)Sentiment Analysis Using a Movie Review Dataset with Keras
and TensorFlow
In this experiment, we'll perform Sentiment Analysis using the IMDb Movie Reviews dataset
provided by Keras. We'll build a basic deep learning model using LSTM (Long Short-Term
Memory) to classify movie reviews as positive or negative.
Steps Involved:
1. Load the Dataset: Use the IMDb dataset provided by Keras.
Requirements:
Make sure you have TensorFlow installed: pip install tensorflow keras Explanation:
1. Dataset:
o We use the IMDb movie reviews dataset, which is a binary classification dataset with
reviews labeled as either positive (1) or negative (0).
2. Preprocessing:
o We limit the number of unique words to 10,000 (num_words=10000).
o All reviews are padded or truncated to have exactly 100 words (pad_sequences).
3. Model: o The model has three layers:
▪ Embedding Layer: Converts input words into dense vectors of fixed size.
▪ LSTM Layer: Processes the sequence of word embeddings.
▪ Dense Layer: Outputs the classification result (positive/negative).
4. Training: o We train the model for 3 epochs using a batch size of 32.
5. Evaluation: o The model is evaluated on the test dataset, and the accuracy is
printed.
How It Works:
• The dataset contains 50,000 movie reviews, split evenly into training and test sets.
• The LSTM network processes the sequence of word embeddings to predict whether a review
is positive or negative.
• The model achieves around 83-85% accuracy after 3 epochs, which can be improved by fine-
tuning parameters or using more sophisticated models.
Further Improvements:
• Use Bidirectional LSTM for better context understanding.
• Experiment with different neural network architectures (e.g., GRU, CNN).
• Apply techniques like Dropout and Regularization to avoid overfitting.
IMPLEMENTATION:
Python Program
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, LSTM, Dense
= 100 # Cut off texts after this number of words (max sequence length) embedding_dim
= 128 # Embedding vector size
# Load data and split into training and test sets
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
# Step 2: Preprocess the Data (Pad sequences to have equal length) x_train
= pad_sequences(x_train, maxlen=maxlen)
optimizer='adam', metrics=['accuracy’])
Output:
PRACTICAL-10
AIM:Perform an experiment using Gensim python library for Word2Vec
Embedding.
IMPLEMENTATION:
OUTPUT: