◐APLab.academy
КурсыИнструментыPremium
··
Войти
APLAB.ACADEMY © 2026 · BUILT BY AP LAB
КУРСЫИНСТРУМЕНТЫКОНФИДЕНЦИАЛЬНОСТЬУСЛОВИЯ
ADVANCED ML: UNSUPERVISED LEARNING & PRODUCTION / L05 — NEURAL NETWORKS FUNDAMENTALS: PERCEPTRONS TO BACKPROPAGATION05 / 12 · ████████░░░░░░░░░░░░ 42%
УРОКИ · 12
01Clustering Algorithms: K-Means, DBSCAN, Hierarchical02Dimensionality Reduction: PCA, t-SNE, UMAP03Anomaly Detection: Isolation Forest & One-Class SVM04Gaussian Mixture Models & EM Algorithm05Neural Networks Fundamentals: Perceptrons to Backpropagation06Deep Learning Basics: Architectures & Training07Time Series Analysis: ARIMA, Prophet, ML Forecasting08Reinforcement Learning Introduction: Q-Learning & Agents09Model Deployment: API Design & Serving Infrastructure10MLOps Fundamentals: Pipelines, Monitoring, Versioning11Model Optimization: Quantization, Pruning, Distillation12Production Best Practices: A/B Testing, Drift, Debugging
НА ЭТОЙ СТРАНИЦЕ
Introduction: The Brain-Inspired RevolutionLearning ObjectivesSee One Before You Build One1. Biological InspirationThe NeuronThe Artificial Neuron2. Neural Network ArchitectureLayers
УРОКИ · 12 · 05 / 12▾
01Clustering Algorithms: K-Means, DBSCAN, Hierarchical02Dimensionality Reduction: PCA, t-SNE, UMAP03Anomaly Detection: Isolation Forest & One-Class SVM04Gaussian Mixture Models & EM Algorithm05Neural Networks Fundamentals: Perceptrons to Backpropagation06Deep Learning Basics: Architectures & Training07Time Series Analysis: ARIMA, Prophet, ML Forecasting08Reinforcement Learning Introduction: Q-Learning & Agents09Model Deployment: API Design & Serving Infrastructure10MLOps Fundamentals: Pipelines, Monitoring, Versioning11Model Optimization: Quantization, Pruning, Distillation12Production Best Practices: A/B Testing, Drift, Debugging
LESSON 05 · ADVANCED · 60 MIN · ◆ 4 INSTRUMENTS

Neural Networks Fundamentals: Perceptrons to Backpropagation

Build neural networks from scratch. Master perceptrons, activation functions, and the backpropagation algorithm with interactive visualizations.

Introduction: The Brain-Inspired Revolution

Traditional machine learning algorithms like linear regression or decision trees follow rigid rules. But what if we could build systems that learn complex patterns, just like our brains?

Neural networks are the foundation of modern AI. They power:

  • Computer Vision: Face recognition, self-driving cars
  • Natural Language: ChatGPT, translation systems
  • Recommendation: Netflix, Spotify, YouTube
  • Healthcare: Disease diagnosis, drug discovery

Key Insight: Neural networks are universal function approximators – given enough neurons and data, they can learn almost any pattern!

Learning Objectives

  • Understand biological inspiration for neural networks
  • Master forward propagation and backpropagation
  • Implement neural networks from scratch
  • Choose appropriate activation functions
  • Understand gradient descent optimization
  • Diagnose and fix training issues
  • Apply neural networks to real problems

See One Before You Build One

Before any of the math, get a feel for what a neural network is: a stack of layers passing numbers forward. The visualizer renders a live network you can reshape and probe.

FIG. 02Neural Network Visualizer
INTERACTIVE
LOADING INSTRUMENT
Fig. 02Visualize neural network architecture and training

Try it: Add a hidden layer (or widen one to 6+ neurons), then click a neuron and watch how its activation — and everything downstream of it — changes. Notice that more neurons means more knobs the network can tune to fit a pattern.


1. Biological Inspiration

TIP

🧠 The single best free intro to backprop ever made: 3Blue1Brown's Neural Networks series — four episodes, ~60 minutes total. Watch episode 1 before continuing. The geometric intuition for "what neurons learn" makes everything below feel obvious.

The Neuron

A biological neuron:

  1. Receives signals through dendrites
  2. Processes them in the cell body
  3. Fires output through the axon if threshold exceeded
  4. Connects to other neurons via synapses

The Artificial Neuron

An artificial neuron (perceptron) mimics this:

  1. Receives inputs x1,x2,...,xnx_1, x_2, ..., x_nx1​,x2​,...,xn​
  2. Computes weighted sum: z=w1x1+w2x2+...+wnxn+bz = w_1x_1 + w_2x_2 + ... + w_nx_n + bz=w1​x1​+w2​x2​+...+wn​xn​+b
  3. Applies activation function: a=f(z)a = f(z)a=f(z)
  4. Outputs aaa to next layer

Mathematical Formula:

a=f(∑i=1nwixi+b)=f(wTx+b)a = f(\sum_{i=1}^{n} w_ix_i + b) = f(w^Tx + b)a=f(i=1∑n​wi​xi​+b)=f(wTx+b)

Where:

  • www = weights (synaptic strengths)
  • bbb = bias (threshold)
  • fff = activation function (firing rule)

2. Neural Network Architecture

Layers

A neural network consists of layers:

  1. Input Layer: Receives raw features
  2. Hidden Layers: Learn intermediate representations
  3. Output Layer: Produces predictions

Deep Learning = neural networks with multiple hidden layers (2+).

Network Topology

Common notation: [3, 4, 4, 2] means:

  • 3 input neurons
  • 2 hidden layers with 4 neurons each
  • 2 output neurons

Interactive Exploration

Now that you know the layer/topology vocabulary, scroll back up to the network visualizer at the top of the lesson and revisit it with fresh eyes:

  1. Click on neurons to see their activations
  2. Adjust the architecture – add/remove layers
  3. Watch forward propagation flow through the network
  4. See how weights affect the output

3. Forward Propagation

The Process

Forward propagation computes the network's output:

For each layer lll:

  1. Compute weighted sum: z[l]=W[l]a[l−1]+b[l]z^{[l]} = W^{[l]}a^{[l-1]} + b^{[l]}z[l]=W[l]a[l−1]+b[l]
  2. Apply activation: a[l]=f(z[l])a^{[l]} = f(z^{[l]})a[l]=f(z[l])

Example (2-layer network):

Layer 1 (Hidden):

z[1]=W[1]x+b[1]z^{[1]} = W^{[1]}x + b^{[1]}z[1]=W[1]x+b[1] a[1]=σ(z[1])a^{[1]} = \sigma(z^{[1]})a[1]=σ(z[1])

Layer 2 (Output):

z[2]=W[2]a[1]+b[2]z^{[2]} = W^{[2]}a^{[1]} + b^{[2]}z[2]=W[2]a[1]+b[2] y^=σ(z[2])\hat{y} = \sigma(z^{[2]})y^​=σ(z[2])

Implementation from Scratch

The whole forward pass is just two lines repeated per layer — a weighted sum, then an activation:

FIG. 04Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 04Interactive Python code execution environment

We'll wrap this into a reusable NeuralNetwork class in the Backpropagation section below, where the forward pass is paired with a backward pass so the network can actually learn.


4. Activation Functions

Why Non-linearity?

Without activation functions, stacking layers is pointless:

a[2]=W[2](W[1]x+b[1])+b[2]=W′x+b′a^{[2]} = W^{[2]}(W^{[1]}x + b^{[1]}) + b^{[2]} = W'x + b'a[2]=W[2](W[1]x+b[1])+b[2]=W′x+b′

This is just a linear transformation! Non-linear activations enable learning complex patterns.

Common Activation Functions

1. Sigmoid

σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}}σ(z)=1+e−z1​
  • Range: (0, 1)
  • Use: Binary classification output
  • Problem: Vanishing gradients

2. Tanh

tanh⁡(z)=ez−e−zez+e−z\tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}}tanh(z)=ez+e−zez−e−z​
  • Range: (-1, 1)
  • Use: Hidden layers (zero-centered)
  • Problem: Vanishing gradients

3. ReLU (Rectified Linear Unit)

ReLU(z)=max⁡(0,z)\text{ReLU}(z) = \max(0, z)ReLU(z)=max(0,z)
  • Range: [0, ∞)
  • Use: Hidden layers (default choice!)
  • Advantages: Fast, no vanishing gradient
  • Problem: Dead neurons

4. Leaky ReLU

Leaky ReLU(z)=max⁡(0.01z,z)\text{Leaky ReLU}(z) = \max(0.01z, z)Leaky ReLU(z)=max(0.01z,z)
  • Solves dead ReLU problem

Visualization

FIG. 06Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 06Interactive Python code execution environment

5. Backpropagation: How Networks Learn

Trace It By Hand First

Before reading the chain-rule notation, walk through it. The Backprop Tracer is a tiny SVG-rendered computational graph with three presets — single-neuron, 2-layer MLP, and softmax+CE. Watch the forward values flow left-to-right (top of each edge), then click Backward and watch the gradients propagate right-to-left (bottom of each edge, in rust).

Click any node to see its local derivative formula with the current numeric values substituted in. The same graph that takes 200 lines of NumPy reduces to a dozen multiplications you can step through.

FIG. 08Backprop Tracer
INTERACTIVE
LOADING INSTRUMENT
Fig. 08Small computational graph with forward + backward pass. Local derivatives, step-by-step.

The Challenge

We want to minimize loss by adjusting weights:

min⁡W,bL(W,b)\min_{W,b} \mathcal{L}(W, b)W,bmin​L(W,b)

But how to compute ∂L∂W[l]\frac{\partial \mathcal{L}}{\partial W^{[l]}}∂W[l]∂L​ for each layer?

The Solution: Chain Rule

Backpropagation applies the chain rule to efficiently compute gradients:

∂L∂W[l]=∂L∂a[l]⋅∂a[l]∂z[l]⋅∂z[l]∂W[l]\frac{\partial \mathcal{L}}{\partial W^{[l]}} = \frac{\partial \mathcal{L}}{\partial a^{[l]}} \cdot \frac{\partial a^{[l]}}{\partial z^{[l]}} \cdot \frac{\partial z^{[l]}}{\partial W^{[l]}}∂W[l]∂L​=∂a[l]∂L​⋅∂z[l]∂a[l]​⋅∂W[l]∂z[l]​

Backward pass:

  1. Compute output error: δ[L]=a[L]−y\delta^{[L]} = a^{[L]} - yδ[L]=a[L]−y
  2. Propagate backward: δ[l]=(W[l+1])Tδ[l+1]⊙f′(z[l])\delta^{[l]} = (W^{[l+1]})^T\delta^{[l+1]} \odot f'(z^{[l]})δ[l]=(W[l+1])Tδ[l+1]⊙f′(z[l])
  3. Compute gradients: ∂L∂W[l]=δ[l](a[l−1])T\frac{\partial \mathcal{L}}{\partial W^{[l]}} = \delta^{[l]}(a^{[l-1]})^T∂W[l]∂L​=δ[l](a[l−1])T

Implementation

FIG. 10Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 10Interactive Python code execution environment

6. Training Dynamics

Drop a Ball, Watch It Roll

The intuition for gradient descent is geometric: the loss surface is a landscape, and the optimizer is a ball rolling downhill. The Loss Landscape Atlas ships five hand-coded analytical surfaces — convex quadratic, Rosenbrock (the banana valley), Himmelblau (four local minima), a saddle, and a multi-modal sin/cos landscape. Click anywhere on the heatmap to drop a ball and watch the optimizer descend.

Try the four optimizers — SGD, momentum, Adam, RMSProp — on Rosenbrock at lr=0.01: only momentum and Adam reliably reach the global minimum. Increase the learning rate and watch SGD diverge.

FIG. 12Loss Landscape Atlas
INTERACTIVE
LOADING INSTRUMENT
Fig. 12Click to drop a ball on five analytical loss surfaces. SGD / momentum / Adam / RMSProp trajectories.

This is the same dynamic that plays out in a million-parameter neural network — projected down to 2D so you can see it.

Gradient Descent

Update rule:

W:=W−α∂L∂WW := W - \alpha \frac{\partial \mathcal{L}}{\partial W}W:=W−α∂W∂L​

Where α\alphaα is the learning rate.

Learning Rate Selection

  • Too small: Slow training, may get stuck
  • Too large: Overshoots minimum, unstable
  • Just right: Smooth, fast convergence

Common Issues

1. Vanishing Gradients

  • Problem: Gradients become tiny in deep networks
  • Solution: Use ReLU, better initialization, batch normalization

2. Exploding Gradients

  • Problem: Gradients become huge
  • Solution: Gradient clipping, careful initialization

3. Overfitting

  • Problem: Memorizes training data
  • Solution: Regularization (dropout, L2), more data

7. Real-World Application: Classification

FIG. 14Python Code Executor
INTERACTIVE
LOADING INSTRUMENT
Fig. 14Interactive Python code execution environment

Key Takeaways

✅ Neural networks are universal function approximators inspired by the brain

✅ Architecture: Input → Hidden layers → Output

✅ Forward propagation: Compute predictions layer by layer

✅ Backpropagation: Efficiently compute gradients using chain rule

✅ Activation functions: Add non-linearity (prefer ReLU for hidden layers)

✅ Training: Gradient descent optimizes weights to minimize loss

✅ Challenges: Vanishing/exploding gradients, overfitting, hyperparameter tuning


What's Next?

Next lesson: Deep Learning Basics – building deeper networks, regularization techniques, and advanced optimizers!


Further Reading

Interactive Visualizations

  • TensorFlow Playground — the most-loved neural-network sandbox on the internet. Add layers, change activations, watch the decision surface morph.
  • ConvNetJS — In-Browser Neural Network Demos — Karpathy's classic. Trains a network in your tab on classification, regression, MNIST, CIFAR.
  • Distill — Why Momentum Really Works — Goh, 2017. Interactive widgets for the optimizers you'll meet in the next lesson.
  • NN-SVG — generate publication-quality network architecture diagrams (FCNN / LeNet / AlexNet style).

Video Courses

  • 3Blue1Brown — Neural Networks Series — 4 episodes, ~60 min total. The single best free intro to backprop on the internet.
  • Andrej Karpathy — Neural Networks: Zero to Hero — code-along videos building backprop from scratch (micrograd), then bigrams, MLPs, and GPTs.
  • StatQuest — Neural Networks Playlist (Josh Starmer).

Papers & Articles

  • A Logical Calculus of the Ideas Immanent in Nervous Activity — McCulloch & Pitts, 1943. The first artificial neuron.
  • Learning representations by back-propagating errors — Rumelhart, Hinton, Williams, Nature 1986.
  • Deep Learning — LeCun, Bengio, Hinton, Nature 2015. The retrospective.
  • The Bitter Lesson — Rich Sutton, 2019. Read this early; it changes how you think about model architecture.

Documentation & Books

  • Book: Deep Learning — Goodfellow, Bengio, Courville (free online).
  • Book: Dive into Deep Learning — Zhang et al. (free, executable).
  • Book: Neural Networks and Deep Learning — Michael Nielsen (free online). Still the gentlest first read.
СВЯЗАННЫЕ ПОНЯТИЯ
neural-networksperceptronbackpropagationdeep-learning
← НАЗАД
04. Gaussian Mixture Models & EM Algorithm
ДАЛЕЕ →
06. Deep Learning Basics: Architectures & Training
ПРИБОРЫ НА СТРАНИЦЕ · 04
FIG. 02 · INTERACTIVE
Neural Network Visualizer
FIG. 04 · INTERACTIVE
Python Code Executor
↺
FIG. 08 · INTERACTIVE
Backprop Tracer
⌒
FIG. 12 · INTERACTIVE
Loss Landscape Atlas
ВАШИ ЗАМЕТКИ