The Feedforward Network
P6.nn-foundations.03 · Audience: guest, language-pro, it-ml · Prerequisites: Activation Functions
A feedforward network (FFN) is a two-layer network with ReLU activation — the basic building block that appears inside every Transformer encoder layer. This module traces its forward pass numerically, from weight matrices through ReLU to the output vector, and then connects it, shape for shape, to the FFN sub-layer of the real Transformer.
In Module 01 you saw a single perceptron: n inputs → one output. A feedforward network (FFN) is a layer of perceptrons running in parallel:
- Layer 1: d_hidden neurons, each receiving all d_in inputs → d_hidden outputs
- Activation: ReLU applied element-wise
- Layer 2: d_out neurons, each receiving all d_hidden values → d_out outputs
The computation is: hidden = ReLU(W₁ · x + b₁), where W₁ is d_hidden × d_in, then output = W₂ · hidden + b₂, where W₂ is d_out × d_hidden. Everything is matrix multiplication plus activation — exactly what GPUs are built for.
🗣️ From a linguist's perspective: The FFN as a two-stage feature transformation pipeline
ⓘ Concept: Feedforward Network (FFN)
Why it matters — The Transformer encoder uses this exact formula — often with d_hidden = 4 × d_model — applied independently to each token position at every encoder layer. In BERT-base: d_model = 768, d_hidden = 3072 (4×).
Q1 — Network vs perceptron: how does a feedforward network differ structurally from a single perceptron?
📚 Go Further
Curated resources to explore feedforward networks further.
| Type | Resource |
|---|---|
| In-app | P10.transformer-architecture.01 — The Encoder Block — the same FFN as sub-layer 2, wrapped in residual connections and LayerNorm, applied to real token embeddings |
| Video | 3Blue1Brown — Gradient descent, how neural networks learn (Deep Learning, Chapter 2, YouTube) |
| Course | Coursera — Deep Learning Specialization, Course 1 Week 3–4: Shallow and Deep Neural Networks, Andrew Ng (free audit) |
| Course | fast.ai — Practical Deep Learning for Coders Lesson 1–2 (free, practical Python focus) |
| Reference | Michael Nielsen, Neural Networks and Deep Learning Ch. 1 (free online at neuralnetworksanddeeplearning.com) |
| Exercise | Karpathy — makemore series on YouTube: build character-level language models from scratch |
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
🎓 Practice ladder
3 graded rungs · ~20 minThree graded rungs: compute one neuron's output by hand, trace a two-layer forward pass with NumPy, then compute cross-entropy loss and its gradient on the network's output.
Rung 1 — One neuron, by hand
Loading exercise…
Rung 2 — Two-layer forward trace
Loading exercise…
Rung 3 — Cross-entropy and its gradient
Loading exercise…
Try it yourself
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Where next?
Later in Neural-Network Foundations