Attention & Transformers

Residual Connections & Skip Connections

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

status: reviewimportance: importantdifficulty 3/5math: undergraduateread: 14mlive demo

Concept Structure

Residual Connections & Skip Connections

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
2next concepts
3related links

Learner Contract

What this page should let you do.

You are here becauseWhy deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

This Attention & Transformers concept is the current object: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | code witness expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Then go nextLayer Normalization & RMSNorm

Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.

Test the linkManipulate one control and predict the visible change.Then continue to Layer Normalization & RMSNorm

Claim/source review status

Claim review not recorded

No structured claim checks yet; source metadata is not enough to establish support.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims0/0 reviewed
Sources0 cited
Codeattached
Demolive
Reviewednot recorded
Updatedpage 2026-06-29

Object flow

4/4 sections readyAsk about thisResearch room
ConceptResidual Connections & Skip ConnectionsAttention & Transformers
Local snapshot ready
concept:attention-transformers/residual-connections
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Without a skip connection, a deep layer has to reinvent the whole representation it receives.

That is a hard optimization problem. If the best thing a layer could do is "mostly keep what already works, and add a small correction," a plain stack has no easy way to express that.

Residual connections make that easy. Instead of asking a layer to learn a full map xyx \mapsto y, we ask it to learn a delta:

y=x+F(x).y = x + F(x).

Now the safe default is clear:

  • if the layer has nothing useful to add, it can make F(x)0F(x) \approx 0,
  • if it has a useful feature, it writes that feature on top of the existing state,
  • the block provides an additive identity path for the current representation, even though later normalization, nonlinearities, finite precision, and downstream updates can still change or overwrite information.

In transformers, this becomes the residual stream mental model: attention and MLP blocks both read the current state, write an update, and pass the shared stream onward.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let xRdx \in \mathbb{R}^d be the input to a block and let F:RdRdF: \mathbb{R}^d \to \mathbb{R}^d be the learned update. A residual block outputs

y=x+F(x).y = x + F(x).

The Jacobian of this mapping is

yx=I+JF(x),\frac{\partial y}{\partial x} = I + J_F(x),

where II is the identity matrix and JF(x)J_F(x) is the Jacobian of FF.

That identity term matters for optimization. Across many layers,

h(+1)=h()+F()(h()),h^{(\ell+1)} = h^{(\ell)} + F^{(\ell)}(h^{(\ell)}),

so backpropagation multiplies matrices of the form I+JF()I + J_{F^{(\ell)}}. Even if the learned part is small or noisy, there is still a direct gradient path through the identity.

For a pre-norm transformer layer, a common pattern is

h=h+Attn(LN(h)),h' = h + \operatorname{Attn}(\operatorname{LN}(h)), hnext=h+MLP(LN(h)).h_{next} = h' + \operatorname{MLP}(\operatorname{LN}(h')).

This says each sublayer writes an update into a shared stream rather than replacing the stream entirely.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

rs = np.random.RandomState(0)
d = 128
depth = 40
x0 = rs.randn(d)
Ws = rs.randn(depth, d, d) / np.sqrt(d)

def cosine(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b) + 1e-12)

def run(residual=True, alpha=0.2):
    h = x0.copy()
    for W in Ws:  # same updates for plain and residual stacks
        update = np.tanh(W @ h)
        h = h + alpha * update if residual else update
    return np.linalg.norm(h), cosine(h, x0)

plain = run(residual=False)
resid = run(residual=True)

print("plain final norm/cosine:", tuple(round(v, 3) for v in plain))
print("resid final norm/cosine:", tuple(round(v, 3) for v in resid))

Residual connections do not magically solve every instability, but they give optimization a much safer default: keep the current representation unless there is a good reason to change it.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the live witness below: set the depth and update scale, then predict which stack keeps the starting signal recognizable. The reveal compares both norm and cosine similarity, because a representation can keep its length while losing its direction. Try the large-update preset after the gentle case; the residual path is a safer default, not a magic guarantee.

Live Concept Demo

Explore Residual Connections & Skip Connections

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Residual Connections & Skip Connections should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Residual Connections & Skip Connections should make visible.

Visual Inquiry

Make the image answer a mathematical question

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Residual Connections & Skip Connections easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

Source gapNo canonical references are listed yet.

Add source metadata before treating this page as source-grounded.

Claim Review

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

StatusSubstantive claim review pending

Source IDs and witness objects are attached for review; they are not proof by themselves.

SourcesNo references

Add source metadata before claiming support.

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Practice Loop

Try the idea before it explains itself

Why deep networks can keep useful features alive: each layer learns a correction to the identity instead of rewriting the whole representation from scratch.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Residual Connections & Skip Connections.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptResidual Connections & Skip ConnectionsAttention & Transformers

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptAttention & Transformers

Residual Connections & Skip Connections

Anchored question

What is the smallest example that makes Residual Connections & Skip Connections click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:attention-transformers/residual-connections.

No local draft saved.
Evidence to inspect
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Residual Connections & Skip Connections Object key: concept:attention-transformers/residual-connections Context: Attention & Transformers Anchor id: concept/concept-notebook/attention-transformers/residual-connections Open question: What is the smallest example that makes Residual Connections & Skip Connections click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/attention-transformers/residual-connections concept:attention-transformers/residual-connections