AI Notes
Master neural network training. Learn epochs, batches, validation, early stopping, hyperparameter tuning. AI fundamentals 2024.
Introduction
Training a neural network means finding the right set of weights and biases that allow the network to make accurate predictions. When a network is first created, its weights are random, producing meaningless outputs. Through an iterative process of making predictions, measuring errors, and adjusting weights, the network gradually learns to map inputs to correct outputs. This process is the heart of all neural network-based AI.
The Training Pipeline
The complete training pipeline follows a well-defined sequence of steps:
| a. Forward pass | compute predictions |
| b. Loss computation | measure error |
| c. Backward pass | compute gradients |
| d. Weight update | adjust parameters |
Loss Functions: Measuring Error
The loss function quantifies how wrong the network's predictions are. Different tasks require different loss functions:
Mean Squared Error (regression)
L = (1/n) Σ (y_predicted - y_actual)²
Cross-Entropy Loss (classification)
L = -(1/n) Σ [y_actual * log(y_predicted) + (1-y_actual) * log(1-y_predicted)]
Example - Binary Classification
True label: 1 (positive)
Network output: 0.9 (90% confident it's positive)
Loss = -[1 * log(0.9) + 0 * log(0.1)] = -log(0.9) = 0.105
If network output: 0.1 (only 10% confident)
Loss = -[1 * log(0.1)] = -log(0.1) = 2.302 ← much higher!
Optimization Algorithms
Stochastic Gradient Descent (SGD)
The simplest optimizer updates weights in the direction that reduces loss:
| - Batch GD: Use all data | stable but slow |
| - Stochastic GD: Use 1 sample | noisy but fast |
| - Mini-batch GD: Use 32-256 samples | best tradeoff |
SGD with Momentum
Momentum accelerates convergence by accumulating past gradients:
Adam Optimizer (Adaptive Moment Estimation)
Adam combines momentum with per-parameter adaptive learning rates:
Worked Example: Training a Simple Network
Let us trace through training a 2-input, 1-hidden-layer (2 neurons), 1-output network for XOR:
| Network: Input(2) | Hidden(2, sigmoid) → Output(1, sigmoid) |
| Training sample | x = [1, 0], target y = 1 (XOR of 1,0 = 1) |
| LOSS | L = -(1×log(0.644)) = 0.440 |
After many iterations, the network converges to weights that correctly compute XOR.
Regularization Techniques
Dropout
During training, randomly set neurons to zero with probability p:
| Training | h = h × mask where mask ~ Bernoulli(1-p) |
| Testing | h = h × (1-p) (scale to match expected output) |
| Effect | Forces redundancy. No single neuron can be relied upon, |
Batch Normalization
Normalize layer inputs to have zero mean and unit variance:
μ_batch = (1/m) Σ x_i
σ²_batch = (1/m) Σ (x_i - μ_batch)²
x̂_i = (x_i - μ_batch) / √(σ²_batch + ε)
y_i = γ × x̂_i + β (learnable scale and shift)
This stabilizes training, allows higher learning rates, and reduces sensitivity to initialization.
Learning Rate Scheduling
The learning rate is arguably the most important hyperparameter:
| Too high | Loss oscillates or diverges |
| Too low | Training takes forever, may get stuck |
| Just right | Smooth convergence to good minimum |
| - Step decay | Reduce lr by factor every N epochs |
| - Cosine annealing | lr_t = lr_min + 0.5(lr_max - lr_min)(1 + cos(πt/T)) |
| - Warm-up | Start low, increase linearly, then decay |
| - ReduceOnPlateau | Reduce when validation loss stops improving |
Common Training Problems and Solutions
| Problem | Symptom | Solution |
|---|---|---|
| Underfitting | High train and val loss | Larger model, more epochs, lower regularization |
| Overfitting | Low train loss, high val loss | Dropout, data augmentation, early stopping |
| Vanishing gradients | Early layers not learning | ReLU, residual connections, batch norm |
| Exploding gradients | NaN loss values | Gradient clipping, lower learning rate |
| Oscillating loss | Loss jumps up and down | Lower learning rate, larger batch size |
Summary
Neural network training transforms randomly initialized parameters into a functioning model through iterative optimization. The process requires careful choices of loss function, optimizer, learning rate, and regularization. Understanding the mechanics of forward passes, loss computation, backpropagation, and weight updates gives you the foundation to diagnose training problems and build effective models. Modern training techniques like Adam, batch normalization, and learning rate scheduling have made training deep networks more reliable, but the fundamentals remain unchanged since the backpropagation algorithm was popularized in the 1980s.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Neural Network Training - Complete Process.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, neural, networks, network, training
Related Artificial Intelligence Topics