Deep Learning Basics Cheat Sheet β€” Neural Networks, Layers, Backprop, Activation Dataplexa
Deep Learning Basics icon

Deep Learning Basics

layers Β· backprop Β· activation Β· dropout Β· optimizers Β· loss

Sheet 1 of 4 Deep Learning Beginner β†’ Intermediate Printable

What Is Deep Learning?

Foundations

Deep Learning is a subset of Machine Learning that uses multi-layered neural networks (deep neural networks) to learn hierarchical representations of data automatically β€” without hand-crafted features.

ConceptSimple Definition
NeuronBasic compute unit: weighted sum + activation
LayerGroup of neurons operating in parallel
Deep Network2+ hidden layers between input and output
ParametersWeights & biases learned during training
EpochOne full pass through the training dataset
BatchSubset of data used per gradient update
ML vs DL: Traditional ML needs feature engineering; deep learning learns features automatically from raw data (pixels, text, audio).

Network Architecture

Structure

A feedforward neural network passes data in one direction β€” from input to output through hidden layers.

Typical Architecture (Keras)
from tensorflow import keras

model = keras.Sequential([
 keras.layers.Input(shape=(784,)), # input
 keras.layers.Dense(256, activation='relu'), # hidden 1
 keras.layers.Dense(128, activation='relu'), # hidden 2
 keras.layers.Dense(64, activation='relu'), # hidden 3
 keras.layers.Dense(10, activation='softmax')# output
])
Neuron Computation
output = activation(W Β· x + b)
W = weight matrix, x = input vector, b = bias term
Rule of thumb: Start with 1–2 hidden layers. Add depth only when underfitting persists after tuning width.

Activation Functions

Non-linearity

Activation functions introduce non-linearity, enabling networks to learn complex patterns beyond linear relationships.

FunctionFormulaUse When
ReLU max(0, x) Default for hidden layers; fast & simple
Leaky ReLU max(Ξ±x, x) Fixes dying ReLU; Ξ±β‰ˆ0.01
Sigmoid 1/(1+e⁻ˣ) Binary classification output only
Tanh (eΛ£βˆ’e⁻ˣ)/(eΛ£+e⁻ˣ) RNNs; zero-centered
Softmax eˣⁱ / Σeˣʲ Multi-class output (probabilities)
GELU xΒ·Ξ¦(x) Transformers, BERT, GPT
Swish xΒ·Οƒ(x) EfficientNet; smooth, bounded below
Dying ReLU: Neurons can get stuck at 0 output permanently. Use Leaky ReLU, ELU, or careful weight init to mitigate.

Backpropagation

Learning Algorithm

Backprop computes gradients of the loss with respect to each weight by applying the chain rule backwards through the network.

  • Forward pass: Compute predictions and loss from input β†’ output.
  • Compute loss gradient: βˆ‚L/βˆ‚Ε· β€” how does loss change with output?
  • Chain rule backward: Propagate gradient layer by layer using βˆ‚L/βˆ‚W = βˆ‚L/βˆ‚a Β· βˆ‚a/βˆ‚z Β· βˆ‚z/βˆ‚W.
  • Update weights: W ← W βˆ’ Ξ· Β· βˆ‚L/βˆ‚W using optimizer.
  • Repeat for each mini-batch until convergence.
Weight Update Rule (SGD)
W ← W βˆ’ Ξ· Β· βˆ‚L/βˆ‚W
Ξ· = learning rate Β· βˆ‚L/βˆ‚W = gradient of loss w.r.t. weight
Vanishing gradient: Gradients shrink exponentially in deep nets with sigmoid/tanh. Fix: use ReLU, batch norm, residual connections, or gradient clipping.

Loss Functions

Objective
LossTaskKeras Name
MSERegressionmse
MAERegression (robust)mae
HuberRegression + outliershuber
Binary CEBinary classificationbinary_crossentropy
Categorical CEMulti-class (one-hot)categorical_crossentropy
Sparse CEMulti-class (int labels)sparse_categorical_crossentropy
KL DivergenceDistribution matchingkl_divergence
Cross-Entropy Loss
L = βˆ’Ξ£ yα΅’ Β· log(Ε·α΅’)
yα΅’ = true label Β· Ε·α΅’ = predicted probability
Compile with Loss
model.compile(
 optimizer='adam',
 loss='sparse_categorical_crossentropy',
 metrics=['accuracy']
)

Optimizers

Gradient Descent
OptimizerKey IdeaBest For
SGDPlain gradient descent Β± momentumCV with tuned LR schedule
MomentumAccumulates velocity in gradient directionSmooth loss landscapes
RMSPropAdapts LR per parameter via moving avgRNNs, non-stationary
AdamMomentum + RMSProp; adaptive LRDefault choice β€” most tasks
AdamWAdam + decoupled weight decayTransformers, NLP
AdagradLarge LR for rare paramsSparse features, NLP
Adam Update Rule
mβ‚œ = β₁mβ‚œβ‚‹β‚ + (1βˆ’Ξ²β‚)gβ‚œ
vβ‚œ = Ξ²β‚‚vβ‚œβ‚‹β‚ + (1βˆ’Ξ²β‚‚)gβ‚œΒ²
W ← W βˆ’ Ξ· Β· mΜ‚β‚œ / (√vΜ‚β‚œ + Ξ΅)
Defaults: β₁=0.9 Β· Ξ²β‚‚=0.999 Β· Ξ΅=1e-8 Β· Ξ·=0.001
Start with Adam lr=1e-3. Switch to SGD+momentum for fine-tuning vision models β€” often yields better generalization.

Dropout

Regularization

Dropout randomly zeroes out neurons during training with probability p, preventing co-adaptation and reducing overfitting.

Dropout in Keras
model = keras.Sequential([
 keras.layers.Dense(256, activation='relu'),
 keras.layers.Dropout(0.3), # drop 30% of neurons
 keras.layers.Dense(128, activation='relu'),
 keras.layers.Dropout(0.2), # lower rate near output
 keras.layers.Dense(10, activation='softmax')
])
RateTypical Usage
0.1–0.2Mild regularization, small models
0.3–0.5Dense layers in large networks
0.5Classic; introduced in original paper
Disabled at inference: Dropout is active only during training. Keras handles this automatically via model.fit() vs model.predict().

Batch Normalization

Stabilization

Batch Norm normalizes layer inputs across a mini-batch to zero mean and unit variance, then applies learnable scale (Ξ³) and shift (Ξ²).

BatchNorm Formula
xΜ‚ = (x βˆ’ ΞΌ_B) / √(σ²_B + Ξ΅)
y = Ξ³ Β· xΜ‚ + Ξ²
ΞΌ_B = batch mean Β· σ²_B = batch variance Β· Ξ³, Ξ² = learned params
BatchNorm in Keras
keras.layers.Dense(256),
keras.layers.BatchNormalization(), # after Dense
keras.layers.Activation('relu'), # activation after BN

Benefits

Higher learning rates Β· Reduces sensitivity to init Β· Acts as regularizer Β· Faster convergence

️ Caveats

Small batches hurt (use Layer Norm) Β· Extra compute Β· Inference uses running stats

Weight Initialization

Setup

Poor initialization causes vanishing or exploding gradients. Use principled schemes that match your activation function.

Init MethodFormula (std)Use With
Xavier / Glorot√(2/(nα΅’β‚™+nβ‚’α΅€β‚œ))Sigmoid, Tanh
He / Kaiming√(2/nα΅’β‚™)ReLU, Leaky ReLU
LeCun√(1/nα΅’β‚™)SELU activation
OrthogonalOrthogonal matrixRNNs, deep nets
Set Initializer in Keras
keras.layers.Dense(
 128, activation='relu',
 kernel_initializer='he_normal' # for ReLU
)
Never initialize all weights to zero β€” all neurons learn identically (symmetry problem). Use random init or the methods above.

Training Process

Pipeline
  • Prepare data: Split train/val/test Β· Normalize inputs Β· Batch & shuffle.
  • Build model: Choose architecture, activations, and init strategy.
  • Compile: Select optimizer, loss function, and evaluation metrics.
  • Train: model.fit() with epochs, batch size, and validation data.
  • Monitor: Plot train vs val loss Β· Watch for overfitting / underfitting.
  • Regularize: Add dropout, batch norm, or L2 if overfitting.
  • Tune: Adjust learning rate, architecture depth/width, batch size.
  • Evaluate: Final metrics on held-out test set β€” never val set.
Full Training Call
history = model.fit(
 X_train, y_train,
 epochs=50,
 batch_size=32,
 validation_data=(X_val, y_val),
 callbacks=[early_stop, lr_scheduler]
)

Overfitting vs Underfitting

Diagnostics
IssueSignsFixes
Overfitting Low train loss, high val loss More data Β· Dropout Β· L1/L2 Β· Early stop Β· Smaller model
Underfitting High train + val loss Bigger model Β· More epochs Β· Lower LR Β· Remove regularization
Good Fit Train β‰ˆ val loss, both low Model generalizes well β€” deploy!
Early Stopping Callback
early_stop = keras.callbacks.EarlyStopping(
 monitor='val_loss',
 patience=5, # wait 5 epochs
 restore_best_weights=True
)
Learning curves are your best diagnostic tool. Always plot training and validation loss together across epochs.

Learning Rate Strategies

Hyperparameter

Learning rate (Ξ·) is the most critical hyperparameter. Too high β†’ diverges. Too low β†’ slow convergence or local minima.

StrategyDescription
ConstantFixed LR throughout training
Step DecayReduce by factor every N epochs
Exponential DecayLR Γ— e^(βˆ’decayΒ·step)
Cosine AnnealingSmooth decay following cosine curve
Warm-up + DecayRamp up then decay; used in Transformers
Cyclical LROscillate between min/max; escapes saddle pts
LR FinderSweep LR; pick value before loss rises
ReduceLROnPlateau Callback
lr_scheduler = keras.callbacks.ReduceLROnPlateau(
 monitor='val_loss', factor=0.5,
 patience=3, min_lr=1e-6
)

Regularization Techniques β€” Full Reference

Prevent Overfitting

L1 & L2 Weight Penalty

L2 (Ridge) Loss
L_total = L + Ξ» Ξ£ wα΅’Β²
L1 uses wα΅’; L1 drives weights to zero (sparse)
Keras
keras.layers.Dense(
 128,
 kernel_regularizer=
 keras.regularizers.l2(0.01)
)

Data Augmentation

Artificially expand training data by applying label-preserving transformations:

Image Augmentation (Keras)
aug = keras.Sequential([
 layers.RandomFlip("horizontal"),
 layers.RandomRotation(0.1),
 layers.RandomZoom(0.1),
 layers.RandomContrast(0.1)
])
NLP: Synonym replacement, back-translation, random masking.

Other Techniques

TechniqueIdea
Early StopHalt when val loss stops improving
DropoutRandom neuron deactivation during train
Batch NormImplicit regularization via normalization
Max-NormClip weight norms to a max value
Label SmoothSoften one-hot targets (0.9 / 0.1)
MixupBlend two training examples + labels

Hyperparameter Quick Reference

Tuning Guide
HyperparameterTypical RangeNotes
Learning Rate1e-4 – 1e-2Most critical; start 1e-3 with Adam
Batch Size16 – 512Larger β†’ stable gradients; smaller β†’ regularizes
Epochs10 – 200+Use early stopping; don't fix arbitrarily
Hidden Units64 – 2048Powers of 2 for GPU efficiency
Layers (depth)2 – 50+Start shallow; go deeper if underfitting
Dropout Rate0.1 – 0.5Tune based on train vs val gap
L2 Ξ»1e-4 – 1e-2Too high β†’ underfitting

Tuning Strategy

  • Random search outperforms grid search when β‰₯3 hyperparameters vary.
  • Bayesian optimization (Optuna, Keras Tuner) is most efficient for expensive models.
  • Fix architecture first, tune LR and batch size, then regularization.
  • Always validate on a separate val set β€” never the test set.
Keras Tuner (Random Search)
import keras_tuner as kt

tuner = kt.RandomSearch(
 build_model,
 objective='val_accuracy',
 max_trials=20
)
tuner.search(X_train, y_train,
 epochs=10, validation_data=(X_val, y_val))

Key Terminology Glossary

Reference
TermMeaning
TensorN-dimensional array (generalized matrix)
GradientPartial derivative of loss w.r.t. a weight
EpochOne full pass through training data
IterationOne batch update (epoch Γ· batch_size)
InferenceRunning model on new data (no training)
TermMeaning
Forward PassInput β†’ output computation
Backward PassLoss gradient β†’ weights via backprop
OverfittingMemorizes train data; fails on new data
UnderfittingModel too simple; misses patterns
CheckpointSaved model weights at a point in training
TermMeaning
Transfer LearningReuse pretrained model on new task
Fine-tuningUnfreeze & retrain pretrained layers
FlattenConvert 2D/3D tensor to 1D vector
LogitsRaw scores before softmax/sigmoid
ConvergenceLoss stops decreasing meaningfully

Deep Learning Basics β€” Mastery Checklist

Self-Assessment

Core Concepts

  • Explain what a neuron computes (WΒ·x + b + activation)
  • Describe the role of each layer type (input, hidden, output)
  • Explain why deep networks outperform shallow ones for complex data
  • Define epoch, batch, and iteration and how they relate
  • Distinguish parameters (weights) from hyperparameters

Training Mechanics

  • Trace the forward pass through a 3-layer network by hand
  • Explain backpropagation and the chain rule in plain English
  • Choose the right loss function for regression vs classification
  • Compare Adam, SGD, and RMSProp and when to use each
  • Read learning curves and diagnose over/underfitting
  • Implement early stopping and LR scheduling callbacks

Regularization & Tuning

  • Apply dropout correctly (train only, not inference)
  • Insert batch normalization in the right position in a layer stack
  • Select He init for ReLU and Xavier for sigmoid/tanh
  • Use L1/L2 regularization and tune Ξ»
  • Explain when random search beats grid search for HPO
  • Run a basic Keras Tuner or Optuna hyperparameter search
Next in Deep Learning Series
Sheet 2 Β· Convolutional Neural Networks (CNN)
convolution Β· pooling Β· filters Β· stride Β· padding Β· ResNet Β· transfer learning
CNN Sheet β†’
← Back