Machine Learning vs. Deep Learning Explained
Machine Learning vs. Deep Learning Explained
Learning?
Machine Learning forms a subset of Artificial Intelligence, where we use statistics and
algorithms to train machines with data, thereby, helping them improve with experience.
Deep Learning is a part of Machine Learning, which involves mimicking the human brain
What is a perceptron?
A perceptron is similar to the actual neuron in the human brain. It receives inputs from
various entities and applies functions to these inputs, which transform them to be the
output.
computes functions based on the weights of the input, and outputs the required
transformation.
Deep Learning?
There are five main steps that determine the learning of a perceptron:
2. Provide inputs
3. Calculate outputs
5. Repeat steps 2 to 4
multi-layer perceptron.
Less efficient with large data Highly efficient with large datasets
Multilayer perceptron
A single layer perceptron can classify only linear separable classes with binary output
(0,1), but MLP can classify nonlinear classes.
Also referred to as “loss” or “error,” cost function is a measure to evaluate how good
your model’s performance is. It’s used to compute the error of the output layer during
backpropagation. We push that error backward through the neural network and use that
during the different training functions.
● Batch gradient descent: Gradient is calculated for the entire dataset, and
● It helps avoid the local minima by allowing the approximation of the gradient
A Feedforward Neural Network signals travel in one direction from input to output. There
are no feedback loops; the network considers only the current input. It cannot memorize
previous inputs (e.g., CNN).
Softmax is an activation function that generates the output between zero and one. It
divides each output, such that the total sum of the outputs is equal to one. Softmax is
often used for output layers.
ReLU (or Rectified Linear Unit) is the most widely used activation function. It gives an
output of X if X is positive and zeros otherwise. ReLU is often used for hidden layers.
A hyperparameter is a parameter whose value is set before the learning process begins.
It determines how a network is trained and the structure of the network (such as the
number of hidden units, the learning rate, epochs, etc.).
● An activation function applies a step rule (convert the numerical output into +1 or -1) to
check if the output of the weighting function is greater than zero or not.
● An activation function of a node defines the output of the node given an input or set of inputs
to the node.
● Activation functions can be divided into three categories:
○ Ridge functions
○ Radial functions, and
○ Fold functions.
● Initializing the weights to zero leads the network to learn zero output which makes the
network not learn anything.
● Initializing the weights to be too large causes the network to experience exploding gradients.
● Initializing the weights to be too small causes the network to experience vanishing gradients.
To find the perfect initialization, there are a few rules of thumb to follow:
What Will Happen If the Learning Rate Is Set Too Low or Too High?
When your learning rate is too low, training of the model will progress very slowly as we
are making minimal updates to the weights. It will take many updates before reaching
the minimum point.
If the learning rate is set too high, this causes undesirable divergent behavior to the loss
function due to drastic updates in weights. It may fail to converge (model can give a
good output) or even diverge (data is too chaotic for the network to train).
The following techniques can be used to reduce model overfitting. (i) Data
augmentation (ii) Dropout (iii) Batch Normalization
Dropout is a technique of dropping out hidden and visible units of a network randomly to
prevent overfitting of data (typically dropping 20 percent of the nodes). It doubles the
number of iterations needed to converge the network.
Batch normalization is the technique to improve the performance and stability of neural
networks by normalizing the inputs in every layer so that they have mean output
activation of zero and standard deviation of one.
The next step on this top Deep Learning interview questions and answers blog will be to
discuss intermediate questions.
dropout value is too low, then it will have minimal effect on learning. If it is too high, then
What Is the Difference Between Batch Gradient Descent and Stochastic Gradient
Descent?
The batch gradient computes the gradient using The stochastic gradient
the entire dataset. computes the gradient using
a single sample.
It takes time to converge because the volume of
data is huge, and weights update slowly. It converges much faster than
the batch gradient because it
updates weight more
frequently.
Overfitting occurs when the model learns the details and noise in the training data to the
degree that it adversely impacts the execution of the model on new information. It is
more likely to occur with nonlinear models that have more flexibility when learning a
target function. An example would be if a model is looking at cars and trucks, but only
recognizes trucks that have a specific box shape. It might not be able to notice a flatbed
truck because there's only a particular kind of truck it saw in training. The model
performs well on training data, but not in the real world.
Underfitting alludes to a model that is neither well-trained on data nor can generalize to
new information. This usually happens when there is less and incorrect data to train a
model. Underfitting has both poor performance and accuracy.
To combat overfitting and underfitting, you can resample the data to estimate the model
accuracy (k-fold cross-validation) and by having a validation dataset to evaluate the
model.
Overfitting is a very common issue when working with Deep Learning. It is a scenario
where the Deep Learning algorithm vigorously hunts through the data to obtain some
valid information.
This makes the Deep Learning model pick up noise rather than useful data, causing
very high variance and low bias. This makes the model less accurate, and this is an
There are two methods here: we can either initialize the weights to zero or assign them
randomly.
Initializing all weights to 0: This makes your model similar to a linear model. All the
neurons and every layer perform the same operation, giving the same output and
making the deep net useless.
Initializing all weights randomly: Here, the weights are assigned randomly by initializing
them very close to 0. It gives better accuracy to the model since every neuron performs
different computations. This is the most commonly used method.
Can we initialize the weights of a network to start from
zero?
use because setting up the weights to zero initially will cause all of the neurons to
produce the same output and the same gradients when performing backpropagation.
This means that the network will not have the ability to learn at all due to the absence of
There are four main layers that form a convolutional neural network:
● Convolution: These are layers consisting of entities called filters that are
convolution layer.
● Pooling: Pooling is the concept of shrinking the complex data entities that
form after convolution and is primarily used to maintain the size of an image
after shrinkage.
● Connectedness: This is used to ensure that all of the layers in the neural
network are fully connected and activation can be computed using the bias
easily.
CNN?
convolution.
● Same padding: Here, padding elements are added all around the output
● Replace the lowest dense layer with a convolutional layer with a kernel size equal to the
layer's input size, with one filter per neuron in the dense layer, and use valid padding.
● Generally, the stride should be 1, but you can set it to a higher value if you want.
● The activation function should be the same as the dense layer's.
● The other dense layers should be converted the same way, but using 1 × 1 filters.
● It is actually possible to convert a trained CNN this way by appropriately reshaping the dense
layers' weight matrices.
While training an RNN, your slope can become either too small or too large; this makes
the training difficult. When the slope is too small, the problem is known as a “Vanishing
Gradient.” When the slope tends to grow exponentially instead of decaying, it’s referred
to as an “Exploding Gradient.” Gradient problems lead to long training times, poor
performance, and low accuracy.
What Is the Difference Between Epoch, Batch, and Iteration in Deep Learning?
● Epoch - Represents one iteration over the entire dataset (everything put into
the training model).
● Batch - Refers to when we cannot pass the entire dataset into the neural
network at once, so we divide the dataset into several batches.
● Iteration - if we have 10,000 images as data and a batch size of 200. then an
epoch should run 50 iterations (10,000 divided by 50).
● VGG-16
● BERT
● GTP-3
● Inception V3
● XCeption
● Autoencoders are used to convert black and white images into colored
images.
● Autoencoder helps to extract features and hidden patterns in the data.
● It is also used to reduce the dimensionality of data.
Autoencoders are artificial neural networks that learn without any supervision. Here,
these networks have the ability to automatically learn by mapping the inputs to the
corresponding outputs.
● Decoder: Used to convert the computational state back into the output
Leaky ReLU is an advanced version of the ReLU activation function. In general, the ReLU
function defines the gradient to be 0 when all the values of inputs are less than zero.
This deactivates the neurons. To overcome this problem, Leaky ReLU activation
functions are used. It has a very small slope for negative values instead of a flat slope.
Data Augmentation is the process of creating new data by enhancing the size and
quality of training datasets to ensure better models can be built using them. There are
different techniques to augment data such as numerical data augmentation, image
augmentation, GAN-based augmentation, and text augmentation.
Why is a convolutional neural network preferred over a dense neural network for
an image classification task?
Which strategy does not prevent a model from over-fitting to the training data?
1. Dropout
2. Pooling
3. Data augmentation
4. Early stopping
Explain two ways to deal with the vanishing gradient problem in a deep neural
network.
Both deep and shallow neural networks can approximate the values of a function. But
the deep neural network is more efficient as it learns something new in every layer. A
shallow neural network has only one hidden layer. But a deep neural network has several
hidden layers that create a deeper representation and computation capability.
If you set the weights to zero, then every neuron at each layer will produce the same
result and the same gradient value during backpropagation. So, the neural network won’t
be able to learn the function as there is no asymmetry between the neurons. Hence,
rHow can you train hyperparameters in a neural network?
Epochs: Denotes the number of times the training data is visible to the neural network to
train.
Momentum: Used to get an idea of the next steps that occur with the data being
executed.
Learning rate: Represents the time required for the network to update the parameters
and learn. randomness to the weight initialization process is crucial.
They are also used to understand parameters, such as the learning rate and the
● Number of hidden layers: Less number of hidden layers may cause underfitting. Increasing
accuracy). If the neural network is large then using dropout will cause the network to learn
● Network Weight Initialization: Initializing the weights according to the activation function
● Activation function: Activation functions give nonlinearity to the neural network. The
activation function is chosen according to the prediction made such as using sigmoid for
popular activation function used by many as Google claims that it outperforms all of the
Exploding gradients are an issue causing a scenario that clumps up the gradients. This
creates a large number of updates of the weights in the model when training.
The working of gradient descent is based on the condition that the updates are small
and controlled. Controlling the updates will directly affect the efficiency of the model.
● Autoencoders
● Boltzmann machines
● Self-organizing maps
● The model is unable to get traction on your training data (e g. poor loss).
● The model is unstable, resulting in large changes in loss from update to update.
● The model loss goes to NaN during training.
If you have these types of problems, you can dig deeper to see if you have a problem with exploding
gradients. There are some less subtle signs that you can use to confirm that you have exploding
gradients:
In this process, BN calculates the mini-batch mean and variance) in every training iteration, therefore
it requires larger batch sizes while training so that it can effectively approximate the population mean
and variance from the mini-batch. This makes BN harder to train networks for applications such as
object detection, semantic segmentation, etc because they generally work with high input resolution
(often as big as 1024 x 2048) and training with larger batch sizes is not computationally feasible.
Moreover, during test (or inference) time, the BN layer doesn’t calculate the mean and variance from
the test data mini-batch but uses the fixed mean and variance calculated from the training data. This
requires caution while using BN and introduces additional complexity.
Answer
● If the neural network has many hidden layers, the gradients in the earlier layers will become
very low as we multiply the derivatives of each layer. As a result, learning in the earlier layers
becomes very slow.
● This can cause the neural network to stop learning.
● This problem of vanishing gradient descent happens when training neural networks with
many layers because the gradient diminishes dramatically as it propagates backwards
through the network.
● Many fixes and workarounds have been proposed and investigated to fix the vanishing
gradient problem, such as
○ alternate weight initialization schemes,
○ unsupervised pre-training,
○ layer-wise training, and
○ variations on gradient descent.
Perhaps the most common change is the use of the rectified linear activation function that has
become the new default, instead of the hyperbolic tangent activation function that was the default
through the late 1990s and 2000s.
Yes. Sigmoid outputs a value between 0 and 1 which makes it a very good choice for
binary classification. You can classify as 0 if the output is less than 0.5 and classify as 1
if the output is more than 0.5. It can be done with tanh as well but it is less convenient
as the output is between -1 and 1.
Does increasing the number of hidden layers improve performance?
Simplistically speaking, accuracy will increase with more hidden layers, but
performance will decrease. But, accuracy not only depends on the number of layers;
accuracy will also depend on the quality of your model and the quality and quantity of
the training data.
Underfitting occurs when there are too few neurons in the hidden layers to adequately
detect the signals in a complicated data set. Using too many neurons in the hidden
layers can result in several problems. First, too many neurons in the hidden layers
may result in overfitting.
Adding a hidden layer between the input and output layers turns the Perceptron into a
universal approximator, which essentially means that it is capable of capturing and
reproducing extremely complex input–output relationships.
The number of layers in a model is referred to as its depth. Increasing the depth
increases the capacity of the model. Training deep models, e.g. those with many
hidden layers, can be computationally more efficient than training a single layer network
with a vast number of nodes.
There are different methods to control overfitting in neural networks. The easy way to
reduce overfitting is by increasing the input data so that neural network training is
on more high-dimensional data. A much as you increase the data, it will stop learning
noise.
Increasing epochs makes sense only if you have a lot of data in your dataset. However,
your model will eventually reach a point where increasing epochs will not improve
accuracy.
Does Too many epochs lead to overfitting?
Too many epochs can lead to overfitting of the training dataset, whereas too few
may result in an underfit model. Early stopping is a method that allows you to specify an
arbitrary large number of training epochs and stop training once the model performance
stops improving on a hold out validation dataset.
This helps in increasing the dataset size and thus reduces overfitting, as we add more
and more data, the model is unable to overfit all the samples and is forced to
generalize.
As they said, there is no "magic" rule to calculate the number of hidden layers and nodes of
Neural Network, but there are some tips or recomendations that can helps you to find the
best ones.
The number of hidden nodes is based on a relationship between:
● Number of input and output nodes
● Amount of training data available
● Complexity of the function that is trying to be learned
● The training algorithm
To minimize the error and have a trained network that generalizes well, you need to pick an
optimal number of hidden layers, as well as nodes in each hidden layer.
● Too few nodes will lead to high error for your system as the predictive factors
might be too complex for a small number of nodes to capture
● Too many nodes will overfit to your training data and not generalize well
Section - How many hidden units should I use?
If your data is linearly separable then you don't need any hidden layers at all. Otherwise
there is a consensus on the performance difference from adding additional hidden layers:
the situations in which performance improves with a second (or third, etc.) hidden layer are
very small. Therefore, one hidden layer is sufficient for the large majority of problems.
There are some empirically-derived rules-of-thumb, of these, the most commonly relied on
is 'the optimal size of the hidden layer is usually between the size of the input and size of
the output layers'.
In sum, for most problems, one could probably get decent performance by setting the
hidden layer configuration using just two rules:
● The number of hidden layers equals one
● The number of neurons in that layer is the mean of the neurons in the input and
output layers.