Deep Learning Notes
Deep Learning Notes
Deep Learning is transforming the way machines understand, learn, and interact with
complex data. Deep learning mimics neural networks of the human brain, it enables
computers to autonomously uncover patterns and make informed decisions from vast
amounts of unstructured data.
In a deep neural network, the input layer receives data, which passes through hidden layers
that transform the data using nonlinear functions. The final output layer generates the
model’s prediction.
The journey of deep learning began with the perceptron, a single-layer neural network
introduced in the 1950s. While innovative, perceptrons could only solve linearly separable
problems, failing at more complex tasks like the XOR problem.
This evolution from perceptrons to MLPs laid the groundwork for advanced architectures like
CNNs and RNNs, showcasing the power of layered structures in solving real-world problems.
1. Feedforward neural networks (FNNs) are the simplest type of ANN, where data flows in
one direction from input to output. It is used for basic tasks like classification.
2. Convolutional Neural Networks (CNNs) are specialized for processing grid-like data,
such as images. CNNs use convolutional layers to detect spatial hierarchies, making them
ideal for computer vision tasks.
3. Recurrent Neural Networks (RNNs) are able to process sequential data, such as time
series and natural language. RNNs have loops to retain information over time, enabling
applications like language modeling and speech recognition. Variants like LSTMs and GRUs
address vanishing gradient issues.
4. Generative Adversarial Networks (GANs) consist of two networks—a generator and a
discriminator—that compete to create realistic data. GANs are widely used for image
generation, style transfer, and data augmentation.
5. Autoencoders are unsupervised networks that learn efficient data encodings. They
compress input data into a latent representation and reconstruct it, useful for dimensionality
reduction and anomaly detection.
3. Scalability: Deep Learning models can scale to handle large and complex datasets,
and can learn from massive amounts of data.
4. Flexibility: Deep Learning models can be applied to a wide range of tasks and can
handle various types of data, such as images, text, and speech.
2. Requires large amounts of labeled data: Deep Learning models often require a
large amount of labeled data for training, which can be expensive and time-
consuming to acquire.
4. Black-box nature: Deep Learning models are often treated as black boxes, making it
difficult to understand how they work and how they arrived at their predictions.
Artificial Neural Networks and its Applications
Artificial Neural Networks contain artificial neurons, which are called units. These units
are arranged in a series of layers that together constitute the whole Artificial Neural
Network in a system. A layer can have only a dozen units or millions of units, as this
depends on how the complex neural networks will be required to learn the hidden patterns in
the dataset. Commonly, an Artificial Neural Network has an input layer, an output layer, as
well as hidden layers. The input layer receives data from the outside world, which the neural
network needs to analyze or learn about. Then, this data passes through one or multiple
hidden layers that transform the input into data that is valuable for the output layer. Finally,
the output layer provides an output in the form of a response of the Artificial Neural
Networks to the input data provided.
In the majority of neural networks, units are interconnected from one layer to another. Each
of these connections has weights that determine the influence of one unit on another unit. As
the data transfers from one unit to another, the neural network learns more and more about
the data, which eventually results in an output from the output layer.
The structures and operations of human neurons serve as the basis for artificial neural
networks. It is also known as neural networks or neural nets. The input layer of an artificial
neural network is the first layer, and it receives input from external sources and releases it to
the hidden layer, which is the second layer. In the hidden layer, each neuron receives input
from the previous layer neurons, computes the weighted sum, and sends it to the neurons in
the next layer. These connections are weighted means effects of the inputs from the previous
layer are optimized more or less by assigning different-different weights to each input and it
is adjusted during the training process by optimizing these weights for improved model
performance.
Artificial neural networks are trained using a training set. For example, suppose you want
to teach an ANN to recognize a cat. Then it is shown thousands of different images of cats so
that the network can learn to identify a cat. Once the neural network has been trained enough
using images of cats, then you need to check if it can identify cat images correctly. This is
done by making the ANN classify the images it is provided by deciding whether they are cat
images or not. The output obtained by the ANN is corroborated by a human-provided
description of whether the image is a cat image or not. If the ANN identifies incorrectly then
is used to adjust whatever it has learned during training. Backpropagation is done by fine-
tuning the weights of the connections in ANN units based on the error rate obtained. This
process continues until the artificial neural network can correctly recognize a cat in an image
with minimal possible error rates.
Feedforward Neural Network : The feedforward neural network is one of the most
basic artificial neural networks. In this ANN, the data or the input provided travels in
a single direction. It enters into the ANN through the input layer and exits through
the output layer while hidden layers may or may not exist. So the feedforward
neural network has a front-propagated wave only and usually does not have
backpropagation.
Radial basis function Neural Network: Radial basis functions are those functions
that consider the distance of a point concerning the center. RBF functions have two
layers. In the first layer, the input is mapped into all the Radial basis functions in the
hidden layer and then the output layer computes the output in the next step. Radial
basis function nets are normally used to model the data that represents any
underlying trend or function.
Recurrent Neural Network: The Recurrent Neural Network saves the output of a
layer and feeds this output back to the input to better predict the outcome of the
layer. The first layer in the RNN is quite similar to the feed-forward neural network
and the recurrent neural network starts once the output of the first layer is
computed. After this layer, each unit will remember some information from the
previous step so that it can act as a memory cell in performing computations.
Social Media: Artificial Neural Networks are used heavily in Social Media. For
example, let’s take the ‘People you may know’ feature on Facebook that suggests
people that you might know in real life so that you can send them friend requests.
Well, this magical effect is achieved by using Artificial Neural Networks that analyze
your profile, your interests, your current friends, and also their friends and various
other factors to calculate the people you might potentially know.
Marketing and Sales: When you log onto E-commerce sites like Amazon and Flipkart,
they will recommend you products to buy based on your previous browsing history.
Similarly, suppose you love Pasta, then Zomato, Swiggy, etc. will show you
restaurant recommendations based on your tastes and previous order history. This is
true across all new-age marketing segments like Book sites, Movie services,
Hospitality sites, etc. and it is done by implementing personalized marketing .
Healthcare: Artificial Neural Networks are used in Oncology to train algorithms that
can identify cancerous tissue at the microscopic level at the same accuracy as trained
physicians. Various rare diseases may manifest in physical characteristics and can be
identified in their premature stages by using Facial Analysis on the patient photos.
Personal Assistants: Personal assistants like Alexa, Siri uses Natural Language
Processing to interact with the users and formulate a response accordingly. Natural
Language Processing uses artificial neural networks that are made to handle many
tasks of these personal assistants such as managing the language syntax, semantics,
correct speech, the conversation that is going on, etc.
They are inspired by the visual processing mechanisms in the human brain, CNNs excel at
capturing hierarchical patterns and spatial dependencies within images.
2. Pooling Layers: They downsample the spatial dimensions of the input, reducing the
computational complexity and the number of parameters in the network. Max
pooling is a common pooling operation, selecting the maximum value from a group
of neighboring pixels.
4. Fully Connected Layers: These layers are responsible for making predictions based
on the high-level features learned by the previous layers. They connect every neuron
in one layer to every neuron in the next layer.
1. Input Image: The CNN receives an input image, which is typically preprocessed to
ensure uniformity in size and format.
2. Convolutional Layers: Filters are applied to the input image to extract features like
edges, textures, and shapes.
3. Pooling Layers: The feature maps generated by the convolutional layers are
downsampled to reduce dimensionality.
4. Fully Connected Layers: The downsampled feature maps are passed through fully
connected layers to produce the final output, such as a classification label.
5. Output: The CNN outputs a prediction, such as the class of the image.
CNNs are trained using a supervised learning approach. This means that the CNN is given a
set of labeled training images. The CNN then learns to map the input images to their correct
labels.
1. Data Preparation: The training images are preprocessed to ensure that they are all in
the same format and size.
2. Loss Function: A loss function is used to measure how well the CNN is performing on
the training data. The loss function is typically calculated by taking the difference
between the predicted labels and the actual labels of the training images.
Applications of CNN
Image segmentation: CNNs can be used to segment images, which means that they
can identify and label different objects in an image. This is useful for applications
such as medical imaging and robotics.
Video analysis: CNNs can be used to analyze videos, such as tracking objects in a
video or detecting events in a video. This is useful for applications such as video
surveillance and traffic monitoring.
Advantages of CNN
Disadvantages of CNN
Complexity: CNNs can be complex and difficult to train, especially for large datasets.
Data Requirements: CNNs need large amounts of labeled data for training.
Recurrent Neural Networks (RNNs) work a bit different from regular neural networks. In
neural network the information flows in one direction from input to output. However in RNN
information is fed back into the system after each step. Think of it like reading a sentence,
when you’re trying to predict the next word you don’t just look at the current word but also
need to remember the words that came before to make accurate guess.
RNNs allow the network to “remember” past information by feeding the output from
one step into next step. This helps the network understand the context of what has
already happened and make better predictions based on that. For example when
predicting the next word in a sentence the RNN uses the previous words to help decide what
word is most likely to come next.
RNNs share similarities in input and output structures with other deep learning architectures
but differ significantly in how information flows from input to output. Unlike traditional deep
neural networks, where each dense layer has distinct weight matrices, RNNs use shared
weights across time steps, allowing them to remember information over sequences.
In RNNs, the hidden state HiHi is calculated for every input XiXi to retain sequential
dependencies. The computations follow these core formulas:
Here, hh represents the current hidden state, UU and WW are weight matrices, and BB is the
bias.
2. Output Calculation:
Y=O(V⋅h+C)Y=O(V⋅h+C)
The output YY is calculated by applying OO, an activation function, to the weighted hidden
state, where VV and CC represent weights and bias.
3. Overall Function:
Y=f(X,h,W,U,V,B,C)Y=f(X,h,W,U,V,B,C)
This function defines the entire RNN operation, where the state matrix SS holds each element
sisi representing the network’s state at each time step ii.
There are four types of RNNs based on the number of inputs and outputs in the network:
1. One-to-One RNN
This is the simplest type of neural network architecture where there is a single input and a
single output. It is used for straightforward classification tasks such as binary classification
where no sequential data is involved.
In a One-to-Many RNN the network processes a single input to produce multiple outputs over
time. This is useful in tasks where one input triggers a sequence of predictions (outputs). For
example in image captioning a single image can be used as input to generate a sequence of
words as a caption.
The Many-to-One RNN receives a sequence of inputs and generates a single output. This
type is useful when the overall context of the input sequence is needed to make one
prediction. In sentiment analysis the model receives a sequence of words (like a sentence)
and produces a single output like positive, negative or neutral.
The Many-to-Many RNN type processes a sequence of inputs and generates a sequence of
outputs. In language translation task a sequence of words in one language is given as input,
and a corresponding sequence in another language is generated as output.
Sequential Memory: RNNs retain information from previous inputs, making them
ideal for time-series predictions where past data is crucial. This capability is often
called Long Short-Term Memory (LSTM).
While RNNs excel at handling sequential data, they face two main training challenges i.e.,
vanishing gradient and exploding gradient problem:
1. Vanishing Gradient: During backpropagation, gradients diminish as they pass
through each time step, leading to minimal weight updates. This limits the RNN’s
ability to learn long-term dependencies, which is crucial for tasks like language
translation.
These challenges can hinder the performance of standard RNNs on complex, long-sequence
tasks.
Natural Language Processing (NLP): RNNs are fundamental in NLP tasks like
language modeling, sentiment analysis, and machine translation.
Image and Video Processing: When combined with convolutional layers, RNNs help
analyze video sequences, facial expressions, and gesture recognition.
Generative Adversarial Networks (GANs) were introduced by Ian Goodfellow and his
colleagues in 2014. GANs are a class of neural networks that autonomously learn patterns in
the input data to generate new examples resembling the original dataset.
1. Generator: creates synthetic data from random noise to produce data so realistic that
the discriminator cannot distinguish it from real data.
2. Discriminator: acts as a critic, evaluating whether the data it receives is real or fake.
They use adversarial training to produce artificial data that is identical to actual data.
The generator is a deep neural network that takes random noise as input to generate realistic
data samples (e.g., images or text). It learns the underlying data distribution by adjusting its
parameters through backpropagation.
The generator’s objective is to produce samples that the discriminator classifies as real. The
loss function is:
JG=−1mΣi=1mlogD(G(zi))JG=−m1Σi=1mlogD(G(zi))
Where,
The generator aims to minimize this loss, encouraging the production of samples
that the discriminator classifies as real (logD(G(zi))(logD(G(zi)), close to 1.
2. Discriminator Model
The discriminator acts as a binary classifier, distinguishing between real and generated
data. It learns to improve its classification ability through training, refining its parameters to
detect fake samples more accurately.
When dealing with image data, the discriminator often employs convolutional layers or
other relevant architectures suited to the data type. These layers help extract features and
enhance the model’s ability to differentiate between real and generated samples.
The discriminator reduces the negative log likelihood of correctly classifying both produced
and real samples. This loss incentivizes the discriminator to accurately categorize generated
samples as fake and real samples with the following equation:
JD=−1mΣi=1mlog D(xi)–1mΣi=1mlog(1–D(G(zi))JD=−m1Σi=1mlogD(xi
)–m1Σi=1mlog(1–D(G(zi))
JDJD assesses the discriminator’s ability to discern between produced and actual
samples.
The log likelihood that the discriminator will accurately categorize real data is
represented by logD(xi)logD(xi).
The log chance that the discriminator would correctly categorize generated samples
as fake is represented by log(1−D(G(zi)))log(1−D(G(zi))).
By minimizing this loss, the discriminator becomes more effective at distinguishing between
real and generated samples.
MinMax Loss
GANs follow a minimax optimization where the generator and discriminator are adversaries:
Actual data samples obtained from the true data distribution pdata(x)pdata(x) are
represented by x.
D(G(z)) is the likelihood that the discriminator will identify generated data coming
from the generator as authentic.
The generator aims to minimize the loss, while the discriminator tries to maximize its
classification accuracy.
Let’s understand how the generator (G) and discriminator (D) complete to improve each
other over time:
1. Generator’s First Move
G takes a random noise vector as input. This noise vector contains random values and acts as
the starting point for G’s creation process. Using its internal layers and learned patterns, G
transforms the noise vector into a new data sample, like a generated image.
2. Discriminator’s Turn
D’s job is to analyze each input and determine whether it’s real data or something G cooked
up. It outputs a probability score between 0 and 1. A score of 1 indicates the data is likely
real, and 0 suggests it’s fake.
3. Adversarial Learning
If the discriminator correctly classifies real data as real and fake data as fake, it
strengthens its ability slightly.
Every time the discriminator misclassifies fake data as real, the generator learns and
improves. Over multiple iterations, the generator produces more convincing synthetic
samples.
5. Discriminator’s Adaptation
The discriminator continuously refines its ability to distinguish real from fake data. This
ongoing duel between the generator and discriminator enhances the overall model’s learning
process.
6. Training Progression
Eventually, the discriminator struggles to distinguish real from fake, indicating that
the GAN has reached a well-trained state.
At this point, the generator can be used to generate high-quality synthetic data for
various applications.
1. Image Synthesis & Generation: GANs generate realistic images, avatars, and high-
resolution visuals by learning patterns from training data. They are widely used in
art, gaming, and AI-driven design.
Advantages of GAN
1. Synthetic data generation: GANs can generate new, synthetic data that resembles
some known data distribution, which can be useful for data augmentation, anomaly
detection, or creative applications.
3. Unsupervised learning: GANs can be trained without labeled data, making them
suitable for unsupervised learning tasks, where labeled data is scarce or difficult to
obtain.
4. Versatility: GANs can be applied to a wide range of tasks, including image synthesis,
text-to-image synthesis, image-to-image translation, anomaly detection, data
augmentation, and others.
In computer vision, deep learning models enable machines to identify and understand visual
data. Some of the main applications of deep learning in computer vision include:
Object detection and recognition: Deep learning models are used to identify and
locate objects within images and videos, making it possible for machines to perform
tasks such as self-driving cars, surveillance, and robotics.
Image classification: Deep learning models can be used to classify images into
categories such as animals, plants, and buildings. This is used in applications such as
medical imaging, quality control, and image retrieval.
Image segmentation: Deep learning models can be used for image segmentation
into different regions, making it possible to identify specific features within images.
2. Natural language processing (NLP)
In NLP, deep learning model enable machines to understand and generate human language.
Some of the main applications of deep learning in NLP include:
Automatic Text Generation: Deep learning model can learn the corpus of text and
new text like summaries, essays can be automatically generated using these trained
models.
Language translation: Deep learning models can translate text from one language to
another, making it possible to communicate with people from different linguistic
backgrounds.
Sentiment analysis: Deep learning models can analyze the sentiment of a piece of
text, making it possible to determine whether the text is positive, negative, or
neutral.
Speech recognition: Deep learning models can recognize and transcribe spoken
words, making it possible to perform tasks such as speech-to-text conversion, voice
search, and voice-controlled devices.
3. Reinforcement learning
Game playing: Deep reinforcement learning models have been able to beat human
experts at games such as Go, Chess, and Atari.
Deep learning has made significant advancements in various fields, but there are still some
challenges that need to be addressed. Here are some of the main challenges in deep learning:
1. Data availability: It requires large amounts of data to learn from. For using deep
learning it’s a big concern to gather as much data for training.
4. Interpretability: Deep learning models are complex, it works like a black box. it is
very difficult to interpret the result.
5. Overfitting: when the model is trained again and again, it becomes too specialized
for the training data, leading to overfitting and poor performance on new data.
Overview: Developed by Google Brain, TensorFlow is one of the most widely used deep
learning frameworks. It supports a range of neural network architectures and is known for its
scalability and flexibility.
Hardware Dependencies:
TPUs: TensorFlow also supports Google’s Tensor Processing Units (TPUs), specialized
hardware designed for accelerating tensor computations. TPUs can significantly
speed up model training and inference, particularly for large-scale models.
Performance Considerations:
TPU: TPUs offer substantial performance improvements for large-scale training and
inference tasks, often outperforming GPUs in speed and efficiency.
PyTorch
Overview: Developed by Facebook’s AI Research lab, PyTorch is known for its dynamic
computation graph and user-friendly interface. It is particularly popular in academic research
due to its flexibility and ease of debugging.
Hardware Dependencies:
GPUs: PyTorch supports NVIDIA GPUs through CUDA, with straightforward APIs for
moving tensors between CPU and GPU. It also offers features like data parallelism
and distributed training.
TPUs: PyTorch has added support for TPUs through the PyTorch/XLA library, allowing
users to leverage TPUs for faster training of large models.
Performance Considerations:
GPU: PyTorch provides efficient GPU utilization with features like automatic mixed
precision and GPU-accelerated operations.
TPU: TPUs can accelerate large-scale models, but integration with PyTorch is less
mature compared to TensorFlow.
Keras
Overview: Keras is a high-level deep learning API that runs on top of several backend
engines, including TensorFlow, Theano, and Microsoft Cognitive Toolkit (CNTK). It is
known for its simplicity and ease of use.
Hardware Dependencies:
GPUs: When used with TensorFlow or other supported backends, Keras can leverage
NVIDIA GPUs for accelerated computations.
TPUs: Keras models can be deployed on TPUs if TensorFlow is used as the backend,
providing the benefits of TPU acceleration.
Performance Considerations:
GPU: Keras benefits from the hardware acceleration capabilities of its backend
engine, such as TensorFlow’s GPU optimizations.
TPU: Performance gains on TPUs depend on the underlying backend engine and the
ability of the Keras model to utilize TPU-specific features.
MXNet
Overview: Apache MXNet is a deep learning framework designed for both efficiency and
scalability. It supports a wide range of programming languages and is known for its high-
performance training capabilities.
Hardware Dependencies:
GPUs: MXNet supports NVIDIA GPUs with CUDA, offering efficient training and
inference through GPU acceleration.
TPUs: MXNet does not have native TPU support but can leverage other hardware
accelerators and distributed computing environments.
Performance Considerations:
GPU: MXNet’s design allows for efficient GPU usage, with features like automatic
parallelism and memory optimizations.
TPU: Without native TPU support, MXNet’s performance improvements are focused
on GPU and multi-machine training scenarios.
Caffe
Overview: Developed by the Berkeley Vision and Learning Center (BVLC), Caffe is a deep
learning framework known for its speed and modularity, particularly in computer vision
tasks.
Hardware Dependencies:
GPUs: Caffe utilizes NVIDIA GPUs for accelerated training, with support for CUDA and
cuDNN libraries to enhance performance.
TPUs: Caffe does not natively support TPUs, focusing primarily on GPU acceleration.
Performance Considerations:
GPU: Caffe provides efficient GPU computation, particularly for convolutional neural
networks (CNNs) used in image processing tasks.
TPU: The lack of TPU support limits Caffe’s ability to leverage Google’s specialized
hardware for acceleration.
Theano
Overview: Theano is an older deep learning library developed by the MILA lab at Université
de Montréal. It allows users to define, optimize, and evaluate mathematical expressions
involving multi-dimensional arrays efficiently. Despite being officially discontinued, it still
forms the basis for many academic and research projects due to its pioneering symbolic
approach.
Hardware Dependencies:
GPUs: Theano supports NVIDIA GPUs through CUDA. While it was one of the first
frameworks to provide such support, it does not feature the most modern
optimizations compared to newer frameworks.
GPU: Offers good performance on GPU architectures available at the time of its last
updates, but lacks behind in modern GPU-specific optimizations.
TPU: No support for TPUs limits Theano to traditional CPU and GPU environments.
Microsoft CNTK
Overview: Microsoft Cognitive Toolkit (CNTK), also known as the Microsoft Cognitive
Toolkit, is a deep learning framework developed by Microsoft Research. It is designed to
handle deep learning tasks at scale, with a focus on speed and efficiency. CNTK supports a
variety of neural network types and is particularly noted for its performance in speech and
image recognition tasks.
Hardware Dependencies:
GPUs: CNTK has robust support for NVIDIA GPUs, utilizing CUDA for accelerating
deep learning computations.
GPU: CNTK is optimized for high performance and scalability on NVIDIA GPUs,
offering advanced capabilities for parallel processing and distributed training.
TPU: Like Theano, the lack of TPU support confines CNTK to CPUs and GPUs.