0% found this document useful (0 votes)
3 views15 pages

Deep Learning Lab Manual

The document outlines various implementations of neural network models for different applications, including XOR problem solving, image classification, digit recognition, face recognition, language modeling, sentiment analysis, machine translation, and image augmentation. Each section describes the aim, methodology, and successful results of the respective implementations. The document emphasizes the use of different neural network architectures such as DNN, CNN, RNN, LSTM, and GANs for these tasks.

Uploaded by

indira.set
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

Deep Learning Lab Manual

The document outlines various implementations of neural network models for different applications, including XOR problem solving, image classification, digit recognition, face recognition, language modeling, sentiment analysis, machine translation, and image augmentation. Each section describes the aim, methodology, and successful results of the respective implementations. The document emphasizes the use of different neural network architectures such as DNN, CNN, RNN, LSTM, and GANs for these tasks.

Uploaded by

indira.set
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link].

1
SOLVING XOR USING DNN

AIM

Implement XOR using Deep Neural Network

DESCRIPTION

Among various logical gates, the XOR or also known as the “exclusive or” problem is one of
the logical operations when performed on binary inputs that yield output for different
combinations of input, and for the same combination of input no output is produced. The
outputs generated by the XOR logic are not linearly separable in the hyperplane.

Let us try to understand the XOR operating logic using a truth table.

From the below truth table it can be inferred that XOR produces an output for different
states of inputs and for the same inputs the XOR logic does not produce any output. The
Output of XOR logic is yielded by the equation as shown below.

X Y Output

0 0 0

0 1 1

1 0 1

1 1 0

Output= X.Y’+X’.Y

The XOR gate can be usually termed as a combination of NOT and AND gates and this type
of logic finds its vast application in cryptography and fault tolerance.

Linear separability of points is the ability to classify the data points in the hyperplane by
avoiding the overlapping of the classes in the planes. Each of the classes should fall above
or below the separating line and then they are termed as linearly separable data points.
With respect to logical gates operations like AND or OR the outputs generated by this logic
are linearly separable in the hyperplane

The linear separable data points appear to be as shown below.


So here we can see that the pink dots and red triangle points in the plot do not overlap each
other and the linear line is easily separating the two classes where the upper boundary of
the plot can be considered as one classification and the below region can be considered as
the other region of classification.

Result

Implementation XOR using Deep Neural Network was done Successfully.


[Link].2
IMAGE CLASSIFICATION USING CNN

AIM

Implement image classification using CNN and Compare its result with RNN

DESCRIPTION

CNNs consist of a series of interconnected layers that process the input data. The first
hidden layer of a CNN is usually a convolutional layer, which applies a set of filters to the
input data to detect specific patterns. Each filter generates a feature map by sliding over the
input data and performing element-wise multiplication with the entries in the filter. These
feature maps are then combined and passed through non-linear activation functions, such
as the ReLU function, which introduces non-linearities into the model and allows it to learn
more complex patterns in the data.

Subsequent layers in a CNN may include additional convolutional layers, pooling layers,
and fully-connected layers. Pooling layers reduce the size of the feature maps. This helps
reduce the overall number of parameters in the model and makes it more computationally
efficient. Fully-connected layers are typically found after convolutional and pooling layers
of a CNN. A fully-connected layer connects all the neurons in a layer to all the neurons in
the next layer, allowing the model to learn possible non-linear combinations of the features
learned by the convolutional layers.

The final layer of a CNN is typically a softmax layer, which produces a probability
distribution across the possible class labels for the input data. The class that has the highest
probability is chosen as the prediction of the model.

RESULT

Thus implement of Image classification using CNN and Compare its result with RNN was
done successfully.
[Link].3
DIGIT RECOGNITION USING CNN

AIM

Implement Digit Recognition using CNN.

DESCRIPTION

Digit recognition using Convolutional Neural Networks (CNNs) is a common task in the
field of computer vision and is often used as a stepping stone for more complex image
recognition tasks. In this response, I'll provide you with a high-level overview of the steps
involved in building a digit recognition system using CNNs.

1. Dataset: To train and test your CNN model for digit recognition, you need a dataset of
labeled digit images. The MNIST dataset is a popular choice, which contains 28x28
grayscale images of handwritten digits (0-9). You can also explore more challenging
datasets like the Fashion MNIST or SVHN (Street View House Numbers).

2. Preprocessing: Preprocess your dataset to make it suitable for training. Common


preprocessing steps include resizing the images to a consistent size, normalizing pixel
values to a range between 0 and 1, and splitting the dataset into training and testing sets.

3. Architecture Design: Design your CNN architecture. A simple architecture might consist
of:

 Convolutional layers: These layers use convolutional filters to learn spatial features
in the images.

 Pooling layers: Pooling layers downsample the feature maps, reducing


computational load.

 Fully connected layers: These layers take the flattened output of the convolutional
layers and make predictions.

RESULT

Implementation of Digit Recognition was done successfully.


[Link].4
FACE RECOGNITION USING CNN

AIM

Implement Face Recognition using CNN.

DESCRIPTION

Face recognition using Convolutional Neural Networks (CNNs) is a popular application of


deep learning in computer vision. Below are the steps to build a face recognition system
using CNNs:

1. Dataset: To create a face recognition system, you need a dataset of labeled face images.
Common datasets include LFW (Labeled Faces in the Wild), VGGFace, and CASIA-WebFace.
If you have a specific use case or want to recognize a particular set of faces, you may need
to create a custom dataset.

2. Preprocessing: Preprocess your face dataset. Common preprocessing steps include


resizing images to a consistent size, normalizing pixel values, and augmenting the data (e.g.,
adding noise, flipping, or rotating images). Additionally, face detection and alignment can
be essential to ensure that faces are consistently positioned and aligned.

3. Architecture Design: Design your CNN architecture. For face recognition, a common
approach is to use a Siamese network or a Triplet network. These networks are designed to
learn embeddings that represent faces in a way that makes them suitable for comparison.
Key components include:

 Base CNN: This part of the network extracts features from face images.

 Embedding Layer: It projects the features into an embedding space where similar
faces are closer and dissimilar faces are farther apart.

RESULT

Implementation of Face Recognition using CNN was done successfully.


[Link].5
LANGUAGE MODELING USING RNN

AIM

Implement Language Modeling using RNN

DESCRIPTION

Language modeling using Recurrent Neural Networks (RNNs) is a fundamental task in


natural language processing (NLP). RNNs are particularly suited for sequential data like
text because they can capture dependencies between words or characters over time. Here's
how you can build a basic language model using RNNs:

1. Data Preparation:

 Text Corpus: Start with a text corpus or dataset. This can be a collection of
sentences, paragraphs, or any text data.

 Tokenization: Split the text into words or subword tokens, which will serve as the
input units for your RNN.

2. Data Preprocessing:

 Vocabulary: Create a vocabulary by assigning a unique integer to each token in


your dataset. You can use libraries like TensorFlow's Tokenizer or NLTK to help
with this.

 Sequences: Convert your text data into sequences of integers representing the
tokens.

3. Model Architecture:

 Define your RNN model. You can choose from various RNN variants, such as vanilla
RNN, LSTM (Long Short-Term Memory), or GRU (Gated Recurrent Unit). LSTM and
GRU are often preferred for better handling of long-range dependencies.

4. Embedding Layer:

 Add an embedding layer as the first layer in your model. This layer learns dense
representations for each token in your vocabulary. These embeddings serve as the
input to the RNN.

5. RNN Layer:

 Stack one or more RNN layers on top of the embedding layer. The RNN layers will
capture sequential dependencies in the text.
6. Dense Layer:

 Add a dense layer with a softmax activation function at the output to predict the
probability distribution of the next token given the previous context. This is used for
language modeling.

7. Training:

 Compile the model with a suitable loss function, such as categorical cross-entropy.
The target for training will be the next token in each sequence.

 Train the model on your text data. You can use techniques like teacher forcing,
where you provide the model with the true previous tokens during training.

8. Hyperparameter Tuning:

 Experiment with hyperparameters like the number of RNN layers, the hidden state
size, the learning rate, and batch size to optimize your model's performance.

9. Text Generation:

 After training, you can use your model to generate text. Start with a seed sentence or
word and use the model to predict the next token. Repeatedly generate tokens and
append them to the input, forming a continuous text generation process.

10. Evaluation:

 Measure the quality of generated text using metrics like perplexity or by examining
the generated text qualitatively.

RESULT

Implementation of Language Modeling using RNN was done successfully.


[Link].6
SENTIMENT ANALYSIS USING LSTM

AIM

Implement Sentiment Analysis using LSTM.

DESCRIPTION

Sentiment analysis using Long Short-Term Memory (LSTM) is a common natural language
processing (NLP) task. LSTM is a type of recurrent neural network (RNN) that is well-
suited for sequence data like text. Sentiment analysis involves determining the sentiment
or emotional tone expressed in a piece of text, such as whether a movie review is positive
or negative. Here's a step-by-step guide on how to perform sentiment analysis using LSTM:

1. Data Preparation:

 Dataset: Gather a labeled dataset for sentiment analysis. Common datasets include
movie reviews, tweets, and product reviews, labeled as positive, negative, or neutral
sentiments.

 Text Preprocessing: Clean and preprocess the text data. Common preprocessing
steps include lowercasing, removing punctuation, and tokenization.

2. Data Preprocessing:

 Tokenization: Split the text into individual words or subword tokens, which will be
used as the input to the LSTM.

 Padding: Ensure that all sequences have the same length by padding or truncating
them. This is necessary for batch processing.

3. Model Architecture:

 Build an LSTM-based model for sentiment analysis. The model typically consists of
the following layers:

 Embedding Layer: To convert words into dense vector representations.

 LSTM Layer(s): To capture sequential information and context in the text.

 Dense Layer: To produce the output (positive or negative sentiment).

4. Model Compilation:

 Compile the model with an appropriate loss function and optimizer. For binary
sentiment classification, binary cross-entropy loss is commonly used. You can use
Adam, SGD, or other optimizers.
5. Training:

 Split your dataset into training, validation, and test sets.

 Train the LSTM model on the training set using the compiled model and the
validation set to monitor model performance.

 Experiment with hyperparameters like the number of LSTM units, the learning rate,
and batch size to optimize model performance.

 Train for a fixed number of epochs or until validation performance converges.

6. Evaluation:

 Evaluate the trained model on the test set to assess its performance in terms of
accuracy, precision, recall, F1-score, or other relevant metrics.

RESULT

Implementation of Sentiment Analysis using LSTM was done successfully.


[Link].7
ENCODER – DECODER MODEL

AIM

Implement Machine Translation using Encoder – Decoder Model.

DESCRIPTION

Seq2Seq (Sequence-to-Sequence) is a type of model in machine learning that is used for


tasks such as machine translation, text summarization, and image captioning. The model
consists of two main components:
 Encoder
 Decoder
Seq2Seq models are trained using a dataset of input-output pairs, where the input is a
sequence of tokens and the output is also a sequence of tokens. The model is trained to
maximize the likelihood of the correct output sequence given the input sequence.
Encoder-Decoder Stack
As the name suggests, seq2seq takes as input a sequence of words(sentence or sentences)
and generates an output sequence of words. It does so by use of the recurrent neural
network (RNN). Although the vanilla version of RNN is rarely used, its more advanced
version i.e. LSTM or GRU is used. This is because RNN suffers from the problem of
vanishing gradient. LSTM is used in the version proposed by Google. It develops the context
of the word by taking 2 inputs at each point in time. One from the user and the other from
its previous output, hence the name recurrent (output goes as input).

The encoder and decoder are typically implemented as Recurrent Neural Networks (RNNs)
or Transformers.

Encoder Stack
It uses deep neural network layers and converts the input words to corresponding hidden
vectors. Each vector represents the current word and the context of the word. The encoder
takes the input sequence, one token at a time, and uses an RNN or transformer to update its
hidden state, which summarizes the information in the input sequence. The final hidden
state of the encoder is then passed as the context vector to the decoder.

Decoder Stack
It is similar to the encoder. It takes as input the hidden vector generated by the encoder, its
own hidden states, and the current word to produce the next hidden vector and finally
predict the next word. The decoder uses the context vector and an initial hidden state to
generate the output sequence, one token at a time. At each time step, the decoder uses the
current hidden state, the context vector, and the previous output token to generate a
probability distribution over the possible next tokens. The token with the highest
probability is then chosen as the output, and the process continues until the end of the
output sequence is reached.
Components of seq2seq Model in Machine Learning
Apart from these two, many optimizations have led to other components of seq2seq:
 Attention: The input to the decoder is a single vector that has to store all the
information about the context. This becomes a problem with large sequences. Hence
the attention mechanism is applied which allows the decoder to look at the input
sequence selectively.
 Beam Search: The highest probability word is selected as the output by the
decoder. But this does not always yield the best results, because of the basic
problem of greedy algorithms. Hence beam search is applied which suggests
possible translations at each step. This is done by making a tree of top k-results.

Bucketing: Variable-length sequences are possible in a seq2seq model because of the


padding of 0’s which is done to both input and output. However, if the max length set by us
is 100 and the sentence is just 3 words long it causes a huge waste of space. So we use the
concept of bucketing. We make buckets of different sizes like (4, 8) (8, 15), and so on,
where 4 is the max input length defined by us and 8 is the max output length defined.

RESULT
Implementation of Machine Translation using Encode – Decoder Model was done
successfully.
[Link].8
IMAGE AUGMENTATION USING GANs

AIM
Implement Image Augmentation using GANs.

DESCRIPTION
Image augmentation using Generative Adversarial Networks (GANs) is a technique that
leverages the power of GANs to generate synthetic data, which can be used to increase the
size and diversity of your dataset. This can be particularly useful in scenarios where you
have limited real data or want to improve the generalization and robustness of machine
learning models.
Here's an overview of how image augmentation with GANs works:
1. Understand GANs: Generative Adversarial Networks consist of two neural
networks – a generator and a discriminator. The generator tries to create realistic
data, while the discriminator tries to distinguish between real and fake data. These
networks are trained simultaneously, leading to a game-like situation where the
generator gets better at creating realistic data over time.
2. Training a GAN: To use GANs for image augmentation, you first need to train a GAN
model. This involves feeding it a dataset of real images and having it generate
synthetic images that resemble the real ones. The GAN is trained iteratively until it
produces convincing synthetic images.
3. Data Augmentation: Once the GAN is trained, you can use it to augment your
dataset by generating new synthetic images. You can generate images with
variations in style, content, lighting, or other relevant factors to make your dataset
more diverse.
4. Mix Real and Synthetic Data: Combine your original dataset with the synthetic
images generated by the GAN to create a larger, more diverse dataset for training
your machine learning model. Ensure that you maintain a balanced and
representative distribution of data classes.
5. Benefits:
 Improved Generalization: The augmented dataset can help your model
generalize better to unseen data, reducing overfitting.
 Enhanced Robustness: Increased diversity in your dataset can make your
model more robust to variations in real-world data.
 Data Expansion: You can significantly increase your dataset size, which is
especially valuable when you have limited real data.
6. Considerations:
 Quality Control: Ensure that the generated images are of sufficient quality
and resemble the characteristics of your real data.
 Diversity: Experiment with different GAN models and training techniques to
create diverse synthetic data.
 Ethical Concerns: Be aware of potential biases and ethical issues in the GAN-
generated data.
7. Tools and Libraries: There are various GAN architectures and libraries available
for image generation, including DCGAN, StyleGAN, and BigGAN. Libraries like
TensorFlow and PyTorch provide GAN implementations for easy use.

8. Fine-Tuning: Depending on your specific task, you might need to fine-tune your
machine learning model with the augmented dataset to ensure it performs
optimally.
Keep in mind that using GANs for data augmentation requires significant computational
resources, as training a GAN can be a resource-intensive process. Additionally, it's essential
to carefully evaluate the impact of data augmentation on your specific machine learning
task to ensure it leads to better model performance.

RESULT
Implementation of Image Augmentation using GANs was done successfully.
[Link].9 MINI PROJECT
(TRANSFER LEARNING)

Transfer Learning

Transfer learning is a machine learning technique where a model trained on one task is
adapted or fine-tuned for a different but related task. Instead of training a model from
scratch for a new task, transfer learning leverages the knowledge acquired from a source
task to improve performance on a target task. This approach is particularly useful when
you have limited data for the target task or want to save computational resources and time.
Here are some key aspects of transfer learning:
1. Pre-trained Model: Transfer learning often starts with a pre-trained model. These
models are typically deep neural networks, like convolutional neural networks
(CNNs) for image tasks or recurrent neural networks (RNNs) for sequential data.
The pre-trained model is trained on a large dataset for a specific task, such as image
classification or natural language processing.
2. Feature Extraction: In transfer learning, the lower layers of the pre-trained model
(often called the feature extractor) are usually frozen, which means they are not
updated during the fine-tuning process. These layers have learned general features
that are valuable for various related tasks. For example, in image recognition, these
lower layers might detect edges, textures, or basic shapes.
3. Fine-tuning: The upper layers of the pre-trained model are replaced or augmented
with new layers to adapt the model for the target task. These new layers are
randomly initialized and then trained on the target dataset. The entire model or a
part of it can be fine-tuned depending on the specific requirements of the task.
4. Choice of Layers: Depending on the similarity between the source and target tasks,
you can choose how many layers to fine-tune. If the tasks are closely related, you
may fine-tune fewer layers. If they are significantly different, you may fine-tune
more layers.
5. Data Augmentation: Data augmentation techniques, such as adding noise, rotating,
flipping, or cropping data, can be employed during fine-tuning to further adapt the
model to the target task and prevent overfitting.
Transfer learning is widely used in various domains, including:
 Computer Vision: Image classification, object detection, and image segmentation.
 Natural Language Processing: Sentiment analysis, text classification, and named
entity recognition.
 Reinforcement Learning: Fine-tuning pre-trained agents for specific tasks.
Common pre-trained models for transfer learning include VGG, ResNet, Inception, BERT,
GPT, and more. These models have achieved state-of-the-art performance on their source
tasks and can be fine-tuned for a wide range of related applications.
Result
Implementation of Transfer Learning was done successfully.

You might also like