0% found this document useful (0 votes)
2 views13 pages

Neural Network Study Guide

Uploaded by

smita06112002
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)
2 views13 pages

Neural Network Study Guide

Uploaded by

smita06112002
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

Neural Network Performance

Complete Study Guide for Exams & Interviews


Simple Language | Key Concepts | 5-Mark Q&A
PART 1: KEY CONCEPTS EXPLAINED SIMPLY

1. Overfitting
Imagine you studied only the previous year's exam paper word-for-word, and on the actual exam, all
questions were rephrased. You'd fail even though you studied hard. That's overfitting — memorizing
instead of understanding.
In neural networks:
• The model learns training data too well, including noise and irrelevant details
• It performs great on training data but poorly on new/unseen data
• Deep networks are more prone to this due to their high complexity

Think of it as: A student who memorizes answers vs one who understands concepts. The memorizer
fails on new questions; the understander adapts.

2. Dropout
Dropout is a technique to prevent overfitting by randomly switching off some neurons during training.
How it works:
• During training: randomly 'drop' (deactivate) a fraction of neurons each iteration
• A dropout rate of 0.5 means 50% of neurons are turned off randomly each time
• This forces remaining neurons to learn useful features independently
• During testing: all neurons are active, but outputs are scaled down

Real-life analogy: Group study where random students are asked to leave each session. The
remaining students must solve problems on their own, making the whole group more capable.

Inverted Dropout (Modern Approach)


• During training: active neurons are scaled UP by dividing by keep probability
• During testing: no scaling needed — simpler and more stable
• Example: dropout=0.5, so keep prob=0.5; active neuron output is multiplied by 2 during training

Key Benefits
• Multiple Subnetworks: Each iteration trains a different subnetwork — like ensemble learning
• Reduced Co-Adaptation: Neurons can't rely on specific other neurons
• Better Generalization: Model works well on unseen data
Typical dropout rates: 0.2-0.5. Use higher rates for large/complex networks, lower for simpler ones.

3. Regularization
Regularization adds a penalty to the loss function to prevent the model from becoming too complex.
Think of it as keeping the model 'in check.'
Core formula: New Loss = Old Loss + λ × Penalty
• λ = 0: no regularization
• Larger λ: stronger regularization, simpler model

L1 Regularization (Lasso)
• Penalty = sum of absolute values of weights: |w1| + |w2| + ...
• Effect: drives unimportant weights to exactly zero (feature selection)
• Result: sparse model — only important features remain
Shopping analogy: Tight budget — you buy only essential items and discard the rest.

L2 Regularization (Ridge)
• Penalty = sum of squared weights: w1² + w2² + ...
• Effect: shrinks all weights toward zero, but none become exactly zero
• Result: balanced model — all features contribute but none dominates
Shopping analogy: Buying smaller quantities of everything — no single item dominates the cart.

Elastic Net
• Combines L1 and L2 using a mixing parameter α (0 to 1)
• α=1 → pure L1 (Lasso), α=0 → pure L2 (Ridge)
• Best for high-dimensional data with highly correlated features

L1 (Lasso) L2 (Ridge)
Absolute value of weights Squared value of weights

Sparse model (some weights → 0) Non-sparse (all weights shrink)

Built-in feature selection No feature selection

Robust to outliers Sensitive to outliers (squaring amplifies)

Good for sparse/high-dimensional data Good for correlated/complex features

Multiple solutions possible Only one solution (convex)


4. Early Stopping
Imagine you're baking a cake. At 30 minutes it's perfect, but if you leave it in for 60 minutes it burns.
Early stopping is like taking it out at exactly the right time.
How it works:
• Split data: training set + validation set
• Monitor validation loss/accuracy at every epoch
• When validation loss starts increasing (model starts overfitting), stop training
• Save the model at its best validation performance — that's your final model

Pros and Cons


• PRO: Simple, effective, works with other techniques, saves computation time
• CON: May stop too early due to fluctuations; needs 'patience' parameter to wait for consistent
degradation

5. Vanishing Gradient Problem


Imagine a game of telephone. By the time a message reaches the first person, it becomes almost
inaudible. That's what happens to gradients in deep networks.
Why it happens:
• In backpropagation, gradients are multiplied across every layer
• If each layer multiplies by a value < 1 (like sigmoid's max derivative of 0.25), gradients shrink
exponentially
• By the time we reach early layers, gradients are nearly zero
• Result: early layers stop learning; network becomes stagnant

Sigmoid derivative is at most 0.25. With 10 layers: 0.25^10 ≈ 0.000001. The gradient has effectively
vanished!

Solution 1: ReLU Activation


• ReLU: f(x) = max(0, x)
• For positive inputs, derivative = 1 — no shrinking!
• Gradients flow through many layers without vanishing
• Drawback: dying ReLU for negative inputs (derivative = 0)
• Fix: Leaky ReLU allows small non-zero gradient for negatives

Solution 2: Proper Weight Initialization


• Xavier/Glorot: for sigmoid/tanh networks
• He Initialization: for ReLU networks

Solution 3: Batch Normalization


• Normalizes inputs of each layer within a mini-batch
• Stabilizes gradient flow, preventing vanishing and exploding

Solution 4: ResNets (Skip Connections)


• Gradients can bypass some layers via skip connections
• Directly flow to earlier layers — smoother gradient propagation

6. Exploding Gradient Problem


The opposite of vanishing gradient. Gradients grow too large during backpropagation, causing unstable
weight updates and training divergence (NaN values).
Why it happens: If weights > 1 and are multiplied repeatedly, gradients grow exponentially.
Mitigation techniques:
• Gradient Clipping: limits gradient values to a fixed range
• Weight Initialization: Xavier or He initialization
• Batch Normalization: normalizes activations, stabilizes training
• Use ReLU: avoids large gradient amplification
• Residual Networks: skip connections for better gradient flow

7. Weight Initialization
Before training, we must set initial weight values. Poor initialization can cause vanishing/exploding
gradients and slow convergence.

Zero/Constant Initialization — Why it FAILS


• All neurons start with same weights → same gradients → same updates
• All neurons learn the same feature (symmetry problem)
• The network behaves like it has just one neuron per layer

Zero initialization fails because symmetry is never broken — all neurons remain identical throughout
training.

Random Initialization — Problems


• Too small weights: activations fall in flat regions of sigmoid/tanh → vanishing gradients
• Too large weights: activations saturate (sigmoid → 0 or 1) → vanishing gradients; or with ReLU →
exploding gradients

Xavier (Glorot) Initialization — For sigmoid/tanh


• Weights drawn from distribution with variance = 2 / (fan_in + fan_out)
• Keeps activation variance balanced across layers
• Prevents activations from becoming too large or too small

He (Kaiming) Initialization — For ReLU


• Uses variance = 2 / fan_in (only considers input neurons)
• The factor '2' compensates for ReLU zeroing out half the activations
• Ensures signal doesn't shrink across layers in ReLU networks
PART 2: JUSTIFY-TYPE 5-MARK QUESTIONS WITH ANSWERS

These questions are designed for both university exams and technical interviews.

Q: Justify: Dropout is an effective regularization technique in deep neural networks. (5 marks)

Answer:
Dropout is justified as an effective regularization technique for the following reasons:

1. Prevention of Co-Adaptation (1 mark): Neurons cannot over-rely on specific neighboring neurons


since different neurons are dropped in every iteration. This forces each neuron to learn
independent, robust features.

2. Ensemble Effect (1 mark): With n neurons and dropout rate 0.5, effectively 2^(n/2) different sub-
networks are trained across iterations. The final model behaves like an ensemble, which is
statistically more accurate and stable.

3. Reduction of Overfitting (1 mark): Since neurons change randomly in each pass, the model cannot
memorize training patterns. It is forced to generalize, improving performance on unseen data.

4. Inverted Dropout for Consistent Scaling (1 mark): During training, active neurons are scaled up
(divided by keep probability) so that the expected output remains unchanged. During testing, all
neurons are active and no additional scaling is needed, ensuring training-testing consistency.

5. Empirical Evidence (1 mark): Dropout has been proven to significantly reduce test error in
benchmark tasks. The network learns more distributed representations, making it less sensitive to
noise and perturbations in input data.

Conclusion: Dropout is both theoretically sound and empirically validated as a powerful


regularization technique.

Q: Justify: L1 regularization performs feature selection while L2 regularization does not. (5 marks)

Answer:
This statement is justified through the mathematical and geometric properties of L1 and L2
penalties:
1. Mathematical Nature of L1 Penalty (1 mark): L1 adds the absolute value of weights (|w|) to the
loss. The gradient of |w| is always +1 or -1, regardless of weight magnitude. This means even very
small weights receive a constant push toward zero and eventually reach exactly zero.

2. Mathematical Nature of L2 Penalty (1 mark): L2 adds squared weights (w²) to the loss. The
gradient is 2w, which is proportional to the weight's magnitude. As weight approaches zero, the
gradient also approaches zero, so the weight asymptotically approaches but never actually reaches
zero.

3. Geometric Interpretation (1 mark): The L1 constraint region forms a diamond (rhombus) shape in
weight space. The loss function's contours are more likely to meet this shape at its corners, where
many weights are zero. L2 forms a circle, and the intersection rarely forces any weight to exactly
zero.

4. Practical Effect of Feature Selection (1 mark): Since L1 drives some weights to zero, the
corresponding features are entirely excluded from the model. This is automatic feature selection. L2
keeps all features but reduces their individual impact.

5. Application Consequences (1 mark): L1 is preferred for high-dimensional datasets with sparse


features (e.g., text data, genomics), where many features are irrelevant. L2 is preferred when all
features are potentially useful or when multicollinearity is a concern.

Conclusion: The key difference is in the geometry of the penalty — L1's absolute value function
creates sparsity; L2's squared function creates shrinkage.

Q: Justify: Zero weight initialization is not suitable for training deep neural networks. (5 marks)

Answer:
Zero initialization is fundamentally flawed for deep networks due to the symmetry problem:

1. Symmetry Problem (1 mark): When all weights are zero, every neuron in a layer receives the same
input and produces the same output. Mathematically, for any two neurons: z1 = x1·0 + x2·0 = 0 and
z2 = x1·0 + x2·0 = 0, so z1 = z2.

2. Identical Gradients During Backpropagation (1 mark): Since all neurons produce the same output,
during backpropagation all neurons receive identical gradients: ∂L/∂w11 = ∂L/∂w21. Therefore, all
weights are updated identically in every epoch.

3. Symmetry is Never Broken (1 mark): Even after multiple iterations, all neurons in a layer remain
identical because they always receive and compute identical updates. The network effectively
behaves as if it has only one neuron per layer, regardless of its actual width.
4. No Feature Diversity (1 mark): A neural network's power comes from different neurons learning
different features. With zero initialization, no feature diversity is possible. For ReLU activation,
ReLU(0) = 0, making all hidden outputs zero and preventing any learning.

5. Why Random Initialization is Needed (1 mark): Random initialization (e.g., He or Xavier) breaks
symmetry by assigning different values to different weights. This allows neurons to diverge and
learn distinct patterns. Proper scaling (not too large, not too small) prevents vanishing/exploding
gradients while maintaining symmetry breaking.

Conclusion: Zero initialization violates the fundamental requirement of symmetry breaking in deep
networks, making it incapable of learning useful representations.

Q: Justify: The vanishing gradient problem makes training deep neural networks difficult, and
explain how ReLU mitigates it. (5 marks)

Answer:
Vanishing gradient is a critical challenge in deep networks, and ReLU provides a principled solution:

1. Why Vanishing Gradient Occurs (1 mark): During backpropagation, gradients are computed by
chaining derivatives across layers (chain rule). If each layer's activation function has a maximum
derivative less than 1 (e.g., sigmoid has max derivative = 0.25), repeated multiplication across L
layers makes the gradient exponentially small: gradient ∝ 0.25^L ≈ 0 for large L.

2. Impact on Training (1 mark): When gradients reach near zero, weight updates become negligible.
The weight update rule is: w_new = w_old - η·(∂L/∂w). If ∂L/∂w ≈ 0, then w_new ≈ w_old — no
learning occurs. Early layers stop learning while later layers continue, leading to inefficient or failed
training.

3. How ReLU Solves It — Gradient Preservation (1 mark): ReLU is defined as f(x) = max(0, x). For
positive inputs, the derivative is exactly 1. Unlike sigmoid (max 0.25) or tanh (max 1 but approaches
0 rapidly), ReLU maintains a gradient of 1, so no gradient shrinkage occurs as it passes through that
neuron.

4. Practical Impact of ReLU (1 mark): In a 10-layer sigmoid network, gradient ∝ 0.25^10 ≈ 10^-6. In a
ReLU network (all positive activations), gradient ∝ 1^10 = 1. This is why ReLU enables training of
very deep networks (100+ layers) that were practically impossible with sigmoid.

5. Limitation and Fix (1 mark): ReLU suffers from the 'dying ReLU' problem — neurons with negative
inputs output 0 with a gradient of 0, potentially becoming permanently inactive. Leaky ReLU
addresses this by allowing a small slope (e.g., 0.01) for negative inputs, ensuring gradient flow even
for negative activations.
Conclusion: Vanishing gradient is fundamentally caused by derivative values less than 1 stacking up
in deep networks. ReLU avoids this by maintaining a derivative of 1 for positive inputs, enabling
effective deep learning.

Q: Justify: Early stopping is a simple yet effective regularization technique for neural networks. (5
marks)

Answer:
Early stopping is justified as an effective regularization method based on both theory and practice:

1. Theoretical Basis (1 mark): During training, a neural network first learns general patterns
(beneficial), then starts memorizing noise (harmful). Validation loss reflects generalization ability —
it decreases during useful learning and increases once overfitting begins. Early stopping targets the
exact moment where generalization is at its peak.

2. Mechanism and Implementation (1 mark): The training data is split into train and validation sets.
At each epoch, validation loss/accuracy is monitored. Training is halted when validation
performance degrades for a set number of consecutive epochs (patience parameter). The model
weights from the best epoch are saved as the final model.

3. Effectiveness as Regularization (1 mark): By limiting the number of training iterations, early


stopping effectively constrains the model's capacity — similar to restricting the hypothesis space.
This reduces variance (overfitting) with minimal increase in bias, which is the core goal of
regularization.

4. Simplicity and Compatibility (1 mark): Unlike L1/L2 which require tuning λ, early stopping requires
only a patience parameter and is compatible with other regularization techniques (dropout, batch
normalization). Modern frameworks like Keras implement it with automatic best-weight saving,
making it trivial to deploy.

5. Practical Advantages (1 mark): Early stopping reduces computation time by avoiding unnecessary
epochs, prevents overfitting without modifying the model architecture, and is model-agnostic —
applicable to any gradient-based learning algorithm. It is especially useful when training time is
expensive.

Conclusion: Early stopping is 'simple' because it requires no model modification, yet 'effective'
because it directly targets the overfitting-generalization trade-off by monitoring held-out
performance.
Q: Justify: Xavier initialization is preferred over random initialization for deep networks using
sigmoid or tanh activations. (5 marks)

Answer:
Xavier initialization is justified as superior to naive random initialization through variance analysis:

1. Problem with Small Random Weights (1 mark): If weights are initialized too small (close to 0),
inputs to activation functions fall near zero. For sigmoid/tanh, these regions have nearly zero
derivatives (flat regions of the S-curve). This causes gradients to vanish during backpropagation,
preventing meaningful weight updates in early layers.

2. Problem with Large Random Weights (1 mark): If weights are too large, inputs to sigmoid/tanh
become very large in magnitude, pushing activations into saturation zones (sigmoid → 0 or 1, tanh
→ -1 or 1). Gradients in these regions also approach zero, again causing vanishing gradients. For
ReLU, large weights cause exploding gradients instead.

3. Xavier's Core Insight — Variance Preservation (1 mark): Xavier initialization sets weight variance
to 2/(fan_in + fan_out). This is mathematically derived to ensure that the variance of activations and
gradients remains approximately equal across all layers, preventing both shrinkage and
amplification of signals as they propagate forward and backward.

4. Formula and Application (1 mark): Weights are drawn from N(0, 2/(fan_in + fan_out)) or U(-
√(6/(fan_in+fan_out)), +√(6/(fan_in+fan_out))). By accounting for both incoming and outgoing
connections, Xavier balances the flow of information in both directions, which is crucial for stable
training with symmetric activation functions like sigmoid and tanh.

5. Empirical Advantage (1 mark): Networks initialized with Xavier converge faster and more reliably
than those with naive random initialization. Training curves are more stable, and the risk of training
failure due to gradient issues is substantially reduced. He initialization extends this idea for ReLU by
using 2/fan_in to compensate for ReLU zeroing negative activations.

Conclusion: Xavier initialization is justified because it is grounded in signal propagation theory,


ensuring activations and gradients maintain appropriate scale throughout the network depth.

Q: Justify: Batch normalization is an effective technique for improving neural network training
stability. (5 marks)

Answer:
Batch normalization addresses fundamental training instabilities in deep networks:
1. Internal Covariate Shift Problem (1 mark): As training progresses, the distribution of inputs to
each layer changes because earlier layers' weights keep updating. This forces each layer to
continuously adapt to new input distributions — a problem called internal covariate shift. This slows
training and makes it unstable.

2. How Batch Normalization Works (1 mark): For each mini-batch, batch normalization normalizes
the inputs to each layer by subtracting the batch mean and dividing by the batch standard deviation.
This ensures each layer always receives inputs with zero mean and unit variance, regardless of what
happened in earlier layers.

3. Gradient Flow Improvement (1 mark): Normalized activations stay within the active range of
activation functions (avoiding saturation). This keeps gradients from vanishing or exploding,
enabling stable and efficient backpropagation even in very deep networks.

4. Regularization Effect (1 mark): Batch normalization introduces slight noise (since mean and
variance are computed over a random mini-batch) which acts like a regularizer, reducing the need
for dropout in some cases. It also makes the network less sensitive to weight initialization, which
previously required very careful tuning.

5. Practical Benefits (1 mark): Batch normalization allows the use of higher learning rates, leading to
faster convergence. It reduces the dependency on careful weight initialization and can reduce or
eliminate the need for dropout. Networks trained with batch normalization consistently achieve
better and more stable accuracy across many benchmark tasks.

Conclusion: Batch normalization is effective because it attacks the root cause of training instability
— distributional shift between layers — while simultaneously providing regularization benefits.

PART 3: QUICK REFERENCE — INTERVIEW CHEAT SHEET

At a Glance: What Each Technique Does


Technique Purpose Key Point
Dropout Reduce overfitting Randomly deactivates neurons during
training; rate 0.2-0.5

L1 (Lasso) Feature selection + regularization Drives weights to zero; sparse model; good
for high-dim data
L2 (Ridge) Weight shrinkage + regularization Shrinks weights smoothly; no zeros; handles
multicollinearity

Elastic Net Best of L1+L2 Mix parameter α controls L1 vs L2 balance

Early Stopping Prevent overfitting Stop when validation loss starts rising; save
best model

ReLU Fix vanishing gradient Derivative = 1 for positive inputs; no


shrinkage

Xavier Init Stable gradients for sigmoid/tanh Variance = 2/(fan_in + fan_out)

He Init Stable gradients for ReLU Variance = 2/fan_in; compensates for ReLU
zeroing

Batch Norm Stabilize training Normalizes per-layer inputs; reduces


covariate shift

Grad Clipping Fix exploding gradients Limits gradient magnitude to fixed range

Remember: Overfitting = high training accuracy, low test accuracy. All these techniques aim to reduce
the gap between training and test performance.

Good luck with your exam and interviews!

You might also like