Docsity

computer security principles and practice global edition, Summaries of Computer Science

Toggle sidebar
bg1
Regularization in Deep Neural Networks
Aspect Description
Core Definition Techniques to prevent๎˜overfitting๎˜(model memorizes training data but fails on new data)
Primary Goal Improve๎˜generalization๎˜- make model perform well on unseen data
Problem
Addressed
Models with too many parameters โ†’ Memorize noise instead of learning patterns
Basic Idea Add๎˜constraints or penalties๎˜to make model simpler/more robust
Trade-off Bias-Variance Tradeoff: Regularization increases bias slightly to reduce variance
significantly
Analogy Studying concepts vs. memorizing textbook answers
WHY REGULARIZATION? THE OVERFITTING PROBLEM:
text
Without Regularization:
Training Accuracy: 98% โœ…
Test Accuracy: 65% โœ… (Overfit!)
With Regularization:
Training Accuracy: 92%
Test Accuracy: 88% โœ… (Generalizes well!)
REGULARIZATION TECHNIQUES
1. PARAMETER PENALTY METHODS
Technique How It Works Effect When to Use
L1 Regularization
(Lasso)
Adds absolute value of
weights to loss:๎˜Loss + ฮปยทโˆ‘|
w|
Feature selection๎˜- forces
some weights to exactly 0
Sparse models,
feature selection
needed
L2 Regularization Adds squared value of Weight decay๎˜- shrinks all General purpose,
pf3
pf4
pf5

Partial preview of the text

Download computer security principles and practice global edition and more Summaries Computer Science in PDF only on Docsity!

Regularization in Deep Neural Networks

Aspect Description Core Definition Techniques to prevent overfitting (model memorizes training data but fails on new data) Primary Goal Improve generalization - make model perform well on unseen data Problem Addressed Models with too many parameters โ†’ Memorize noise instead of learning patterns Basic Idea Add constraints or penalties to make model simpler/more robust Trade-off Bias-Variance Tradeoff : Regularization increases bias slightly to reduce variance significantly Analogy Studying concepts vs. memorizing textbook answers WHY REGULARIZATION? THE OVERFITTING PROBLEM: text Without Regularization: Training Accuracy: 98% โœ… Test Accuracy: 65% โœ… (Overfit!) With Regularization: Training Accuracy: 92% Test Accuracy: 88% โœ… (Generalizes well!) REGULARIZATION TECHNIQUES

1. PARAMETER PENALTY METHODS Technique How It Works Effect When to Use L1 Regularization (Lasso) Adds absolute value of weights to loss: Loss + ฮปยทโˆ‘| w| Feature selection - forces some weights to exactly 0 Sparse models, feature selection needed L2 Regularization (^) Adds squared value of Weight decay - shrinks all General purpose,

Technique How It Works Effect When to Use (Ridge) (^) weights: Loss + ฮปยทโˆ‘wยฒ weights proportionally most common Elastic Net Combines L1 + L2: Loss + ฮป ยทโˆ‘|w| + ฮป ยทโˆ‘wยฒโ‚ โ‚‚ Balance of sparsity and shrinkage When unsure between L1/L Visual: text L1: Encourages โ†’ [0, 0.3, 0, 0.7, 0] (sparse) L2: Encourages โ†’ [0.1, 0.2, 0.1, 0.3, 0.1] (small values)

2. ARCHITECTURAL METHODS Technique How It Works Effect Key Parameters Dropout Randomly "drop" neurons during training (set to 0) Prevents co-adaptation, ensemble effect Dropout rate (0.2-0.5) DropConnect Randomly drop connections (weights) instead of neurons Similar to dropout but at weight level Drop probability Stochastic Depth Randomly skip layers during training Ensures all layers learn useful features Survival probability per layer Dropout Example: text Training: Each neuron has 20% chance of being turned off Testing: All neurons active, but weights scaled by 0. 3. DATA-BASED METHODS Technique How It Works Effect Variations Data (^) Artificially expand dataset Teaches invariance to Image: rotations, flips,

Technique How It Works Effect Implementation Weight Constraints Enforce hard limits on weight values Prevents exploding weights Max norm constraint, non- negativity constraints Early Stopping Visualization: text Epochs: 1 2 3 4 5 6 7 8 9 10 Train Loss: โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ Val Loss: โ†˜ โ†˜ โ†˜ โ†˜ โ†˜ โ†— โ†— โ†— โ†— โ†— Stop here! โ†’ โ†‘

5. ENSEMBLE METHODS Technique How It Works Effect Variants Model Averaging Train multiple models, average predictions Reduces variance, improves stability Independent training, different initializations Bagging Train on bootstrap samples of data Reduces variance, handles noisy data Random Forests (for decision trees) Snapshot Ensembles Save model snapshots during training, ensemble them Multiple models for price of one Cyclical learning rates 6. SPECIALIZED TECHNIQUES Technique Best For How It Works Key Insight Label Smoothing Classification Replace hard 0/1 labels with soft targets (0.9/0.1) Prevents overconfidence Gradient Clipping RNNs, unstable training Clip gradients to maximum value Prevents exploding gradients

Technique Best For How It Works Key Insight Spatial Dropout CNNs Drop entire feature maps instead of individual pixels Respects spatial correlations Variational Dropout Bayesian NNs Learn dropout rate per weight Adaptive regularization PRACTICAL COMPARISON: Scenario Recommended Techniques Why Computer Vision Dropout, Data Augmentation, Batch Norm, CutMix Images have natural invariances, CNNs prone to overfitting Natural Language Dropout, Weight Decay (L2), Label Smoothing Text data often limited, models easily memorize Small Dataset Heavy Data Augmentation, Early Stopping, L Need to maximize information from limited data Large Dataset Moderate Dropout, Batch Norm, L2 Enough data, need to control capacity Recurrent Networks Dropout (variational), Gradient Clipping, Weight Tying RNNs particularly prone to overfitting Transfer Learning Fine-tuning with L2, Early Stopping, Partial freezing Pre-trained features, need to adapt carefully IMPLEMENTATION IN CODE: python _# Common regularization in Keras/TensorFlow

L2 Regularization_

Parameter Typical Range Effect if Too High Effect if Too Low Early Stopping Patience

epochs Early stopping (under-trained) Overfitting Batch Size 32 - 256 Less regularization (smoother gradients) More regularization (noisy gradients) MODERN TRENDS:

  1. Batch Normalization โ†’ Layer Normalization (for sequences)
  2. Dropout โ†’ SpatialDropout (for CNNs), Variational Dropout
  3. Data Augmentation โ†’ AutoAugment (learned augmentations)
  4. Mixup & CutMix becoming standard for vision tasks
  5. Self-supervised learning as implicit regularization KEY PRINCIPLES:
  6. Simpler models generalize better (Occam's Razor)
  7. Noise during training โ†’ robustness during testing
  8. Multiple weak learners better than one strong learner
  9. Constraint creativity โ†’ better generalization RULE OF THUMB: Start with: L2 regularization + Dropout + Data Augmentation + Early Stopping Tune: Regularization strength based on validation performance Monitor: Gap between training and validation accuracy Goal: Small gap (5-10%) with good validation performance Remember: Regularization is like training wheels - essential when learning, but as your model/data improves, you might need less of it!