Skip to content
AriadneTechnology

The Middle Ring · Chamber 4 of 9

Functions: Machines That Map

Domains, codomains, composition and inverses: how papers write down models, activations and layers.

35 min 50 XP + 12 questions + 1 challengeNotationVideoPapersProofsCodeLab

In this chamber you will

  • Read f : X → Y, x ↦ f(x) and f(x; θ)
  • Compose functions and explain why order matters
  • Use exp, log and their rules fluently
  • Read activation functions and residual blocks as functions
DiscoverLearnRead beyondPapers & lecturesYour turn

Discover: the most cited line of the century

In December 2015, four researchers at Microsoft Research posted a paper about training very deep networks. A 2025 analysis by Nature found it to be the most cited paper of the twenty-first century. Its central idea fits on one line:

Spotted in the wild

y=F(x,{Wi})+x\mathbf{y} = \mathcal{F}(\mathbf{x}, \{W_i\}) + \mathbf{x}
He, Zhang, Ren & Sun (2016), “Deep Residual Learning for Image Recognition”, Eq. (1)

Read it aloud with what you already know: “bold y equals calligraphic F of bold x and the set of W sub i, plus bold x.” The bold letters are vectors (Chamber 1). The braces make a set (Chamber 2): {Wi}\{W_i\} is the collection of weight matrices inside the block. And F\mathcal{F} is a function: a machine that takes the input x\mathbf{x} and the weights, and returns a vector. The block's output is its input plus whatever F\mathcal{F} computes.

Why did one “+ x+\,\mathbf{x}” matter so much? Before this paper, simply stacking more layers could make a network worse: the paper's Figure 1 shows a 56-layer network with higher training error than a 20-layer one. With the shortcut, the authors trained networks 152 layers deep and won the 2015 ImageNet competition.

This chamber gives you the language to see why. A network is a chain of machines, and the notation for machines, chains and undoing machines is the notation of functions. Here's a first taste. Suppose the block's learned function gives up and outputs zero, whatever it's fed.

Quick check +20 XP

Suppose the learned function F\mathcal{F} in y=F(x,{Wi})+x\mathbf{y} = \mathcal{F}(\mathbf{x}, \{W_i\}) + \mathbf{x} outputs the zero vector for every input. What does the block compute?

DiscoverLearnRead beyondPapers & lecturesYour turn

Learn: a function is a machine with a contract

Papers announce a function with a line like

f:R→R,x↦x2.f : \mathbb{R} \to \mathbb{R}, \qquad x \mapsto x^2.

Read it as “ff maps the real numbers to the real numbers, sending xx to xx squared.” The first half is the contract: XX, before the arrow, is the domain (the inputs ff accepts) and YY, after it, is the codomain (where outputs are promised to land). The second half is the rule. Notice the two arrows. The plain arrow →\to connects whole sets. The arrow with a little tail, ↦\mapsto (“maps to”), connects a single input to its output.

The codomain is a promise, not a description. Squares are never negative, so this ff only ever produces numbers in [0,∞)[0, \infty). The set of outputs a function actually produces is its image, written f(X)={f(x):x∈X}f(X) = \{f(x) : x \in X\} with the set-builder notation of Chamber 2. Here the codomain is R\mathbb{R} and the image is [0,∞)[0, \infty).

A rule can break the contract in two ways. It can leave an input without an output: log⁡x\log x has no value at x=0x = 0, so we shrink the domain and write log⁡:(0,∞)→R\log : (0, \infty) \to \mathbb{R}. Or it can give an input two outputs: “the number whose square is 4” could be 2 or −2-2, so it isn't a function until you choose one. That's why x\sqrt{x} always means the non-negative root.

In machine learning, everything is a function. A digit classifier is f:R784→{0,1,…,9}f : \mathbb{R}^{784} \to \{0, 1, \ldots, 9\}: a flattened 28×2828 \times 28 image goes in, a label comes out. A loss is L:Rd→R\mathcal{L} : \mathbb{R}^{d} \to \mathbb{R}: a setting of dd parameters goes in, one number comes out. Reading the contract first tells you what kind of object you're dealing with before you look at a single formula.

Functions
  • f:X→Yf : X \to Y“f from X to Y”
    A function named ff with domain XX (the allowed inputs) and codomain YY (where outputs are promised to live). Every input gets exactly one output.
    f:R→Rf : \mathbb{R} \to \mathbb{R}
  • x↦x2x \mapsto x^2“x maps to x squared”
    The rule: what happens to a single input. This arrow has a little tail; the plain arrow →\to connects whole sets.
    f:x↦x2f : x \mapsto x^2
  • f(x)f(x)“f of x”
    The output of ff at the input xx. The brackets mean “of”, not multiplication.
    f(3)=9f(3) = 9
  • f(X)f(X)“the image of X under f”
    The set of outputs ff actually produces, {f(x):x∈X}\{f(x) : x \in X\}. It sits inside the codomain and can be smaller.
    f(R)=[0,∞)f(\mathbb{R}) = [0, \infty)
  • f(x;θ)f(x; \theta)“f of x semicolon theta”
    A model: the input xx before the semicolon, the parameters θ\theta after it. Training changes θ\theta; prediction changes xx.
    f(x;θ)f(\mathbf{x}; \theta)
  • fθ(x)f_\theta(x)“f sub theta of x”
    The same idea with the parameters as a subscript: one function for every choice of θ\theta.
    fθ(x)f_\theta(\mathbf{x})
  • f(x,y)f(x, y)“f of x and y”
    A function of two inputs. Its domain is a Cartesian product such as R×R\mathbb{R} \times \mathbb{R} (Chamber 2).
    L^(N,D)\hat{L}(N, D)
Quick check +20 XP

Take f:R→Rf : \mathbb{R} \to \mathbb{R}, x↦x2x \mapsto x^2. Which statement is right?

Learn: inputs, parameters and the semicolon

A model is a function with knobs. The input is what you feed it at prediction time; the parameters are the knobs that training turns. Papers separate the two in a few standard ways:

  • f(x;θ)f(\mathbf{x}; \theta), “f of x, semicolon theta”. The semicolon splits the inputs (before it) from the parameters (after it).
  • fθ(x)f_\theta(\mathbf{x}), “f sub theta of x”. The same idea: a whole family of functions, one for each θ\theta.
  • f(x,θ)f(\mathbf{x}, \theta), with a plain comma. ResNet's F(x,{Wi})\mathcal{F}(\mathbf{x}, \{W_i\}) is written this way, and you rely on the text to know which argument is which.

The distinction matters because the two kinds of input change at different times. When the model predicts, θ\theta is fixed and x\mathbf{x} varies. When it trains, the data is fixed and θ\theta varies. That's why the loss is usually written L(θ)\mathcal{L}(\theta), a function of the parameters alone, even though it depends on data too.

Functions can take several inputs. g:R×R→Rg : \mathbb{R} \times \mathbb{R} \to \mathbb{R}, (x,y)↦x2+y2(x, y) \mapsto x^2 + y^2 takes a pair; its domain is the Cartesian product from Chamber 2. You'll meet a famous two-input function later in this chamber, a formula that predicts a language model's loss from its size and its amount of data.

Learn: composition, machines in a chain

Feed the output of one machine into another and you get a new machine. That's composition:

(f∘g)(x)=f(g(x)).(f \circ g)(x) = f(g(x)).

Say f∘gf \circ g as “f composed with g”, or better, “f after g”. The small circle is not multiplication, and the order is the whole point. In f(g(x))f(g(x)), the function nearest to xx acts first. So the notation reads right to left, even though you read the page left to right.

Take g(x)=x+1g(x) = x + 1 and f(x)=x2f(x) = x^2. Then

(f∘g)(x)=f(x+1)=(x+1)2,(g∘f)(x)=g(x2)=x2+1.(f \circ g)(x) = f(x + 1) = (x + 1)^2, \qquad (g \circ f)(x) = g(x^2) = x^2 + 1.

At x=1x = 1 the first gives 4 and the second gives 2. Same two machines, different order, different function: composition is not commutative. The lab below turns this into a game. Build each target by chaining machines, and keep an eye on the pipeline, which runs left to right, and the notation, which runs right to left.

Interactive lab

Function composer

Each machine is a function. Feed x through up to three of them and compare the result with the target curve. The pipeline runs left to right, the way x travels. The notation runs right to left: in f ∘ g, the machine g acts first.

Targets

Shift, then square. Two machines. The one that touches x first is written on the right.

Machines

Pipeline

  1. x
  2. empty1st
  3. empty2nd
  4. empty3rd
  5. y
id(x)=x\mathrm{id}(x) = x
-3-2-10123-30369

target your composition

machines

0 / 3

points matched

0 / 121

targets built

0 / 4

Click a machine to feed x into it. Click more to chain them (up to three).

Challenge: Function composerBuild all four target functions by composing the machines.+40 XP

Composition is how deep networks are built. A network with LL layers is

f=fL∘⋯∘f2∘f1,f = f_L \circ \cdots \circ f_2 \circ f_1,

where each layer is itself a small composition, such as fℓ(h)=σ(Wℓh+bℓ)f_\ell(\mathbf{h}) = \sigma(W_\ell \mathbf{h} + \mathbf{b}_\ell): multiply by a matrix, add a vector, apply an activation. The input enters on the right and the prediction leaves on the left.

One machine deserves a name of its own: the identity id(x)=x\mathrm{id}(x) = x, which changes nothing. Composing with it changes nothing either: f∘id=id∘f=ff \circ \mathrm{id} = \mathrm{id} \circ f = f. ResNet's block is the identity plus a correction, x↦x+F(x)\mathbf{x} \mapsto \mathbf{x} + \mathcal{F}(\mathbf{x}). If F\mathcal{F} learns nothing useful it can fall back to zero and the block becomes id\mathrm{id}, so adding blocks shouldn't make a network worse. As the paper puts it, “if an identity mapping were optimal, it would be easier to push the residual to zero than to fit an identity mapping by a stack of nonlinear layers.”

A proof: brackets don't matter, order does

Why can we write f∘g∘hf \circ g \circ h with no brackets at all? Because composition is associative, and here's the complete proof.

Claim. Composition is associative. For any functions h:W→Xh : W \to X, g:X→Yg : X \to Y and f:Y→Zf : Y \to Z,

(f∘g)∘h=f∘(g∘h).(f \circ g) \circ h = f \circ (g \circ h).

Two functions are equal when they have the same domain and give the same output for every input. Both sides here take inputs from WW, so it's enough to compare outputs.

Proof. Let xx be any element of WW. Apply the definition of ∘\circ twice to the left-hand side, first with f∘gf \circ g as the outer function:

((f∘g)∘h)(x)=(f∘g)(h(x))=f(g(h(x))).\big((f \circ g) \circ h\big)(x) = (f \circ g)\big(h(x)\big) = f\Big(g\big(h(x)\big)\Big).

Now do the same on the right-hand side, this time with g∘hg \circ h as the inner function:

(f∘(g∘h))(x)=f((g∘h)(x))=f(g(h(x))).\big(f \circ (g \circ h)\big)(x) = f\big((g \circ h)(x)\big) = f\Big(g\big(h(x)\big)\Big).

Both sides equal f(g(h(x)))f(g(h(x))), and xx was arbitrary, so the two functions are equal. ■\blacksquare

The proof is short because it only unpacks a definition, which is what many good proofs do. Its message for networks: you may group layers any way you like (into “blocks”, say), but you may not reorder them.

Quick check +20 XP

Let f(x)=2xf(x) = 2x and g(x)=x2−1g(x) = x^2 - 1. What is (f∘g)(3)(f \circ g)(3)?

Learn: inverses, undoing a machine

The inverse of ff, written f−1f^{-1} and read “f inverse”, is the machine that undoes it:

f−1(f(x))=xandf(f−1(y))=y,that is,f−1∘f=id.f^{-1}(f(x)) = x \quad\text{and}\quad f(f^{-1}(y)) = y, \qquad\text{that is,}\qquad f^{-1} \circ f = \mathrm{id}.

Not every function can be undone. If two inputs land on the same output, no machine can tell which one you started from. A function that never does this is injective (one-to-one): f(a)=f(b)f(a) = f(b) implies a=ba = b. A function whose image is its whole codomain is surjective (onto). A function that is both is bijective, and those are exactly the functions with an inverse. Three examples you'll meet again:

  • x↦x2x \mapsto x^2 on R\mathbb{R} isn't injective, since (−2)2=22(-2)^2 = 2^2. Restrict it to [0,∞)→[0,∞)[0, \infty) \to [0, \infty) and it becomes bijective, with inverse y\sqrt{y}.
  • ReLU\mathrm{ReLU} sends every negative number to 0. Once a ReLU outputs 0, the input is gone for good.
  • exp⁡:R→(0,∞)\exp : \mathbb{R} \to (0, \infty) is bijective. Its inverse is log⁡:(0,∞)→R\log : (0, \infty) \to \mathbb{R}, which is how the logarithm is defined.

A derivation: the inverse of the sigmoid

The sigmoid σ(x)=11+e−x\sigma(x) = \frac{1}{1 + e^{-x}} squashes every real number into (0,1)(0, 1), and it's strictly increasing, so it has an inverse. To find it, solve y=σ(x)y = \sigma(x) for xx, where 0<y<10 < y < 1:

y=11+e−xthe definition1+e−x=1ytake reciprocals of both sides (both are positive)e−x=1y−1=1−yysubtract 1−x=log⁡1−yytake logs (the right side is positive)x=log⁡y1−ysince −log⁡ab=log⁡ba.\begin{aligned} y &= \frac{1}{1 + e^{-x}} && \text{the definition} \\[6pt] 1 + e^{-x} &= \frac{1}{y} && \text{take reciprocals of both sides (both are positive)} \\[6pt] e^{-x} &= \frac{1}{y} - 1 = \frac{1 - y}{y} && \text{subtract 1} \\[6pt] -x &= \log\frac{1 - y}{y} && \text{take logs (the right side is positive)} \\[6pt] x &= \log\frac{y}{1 - y} && \text{since } -\log\tfrac{a}{b} = \log\tfrac{b}{a}. \end{aligned}

So σ−1(y)=log⁡y1−y\sigma^{-1}(y) = \log\frac{y}{1 - y}, defined for yy in (0,1)(0, 1). Check it: σ(0)=12\sigma(0) = \frac{1}{2}, and log⁡1/21/2=log⁡1=0\log\frac{1/2}{1/2} = \log 1 = 0. This function is the logit.

Undoing a chain works like taking off socks and shoes: whatever went on last comes off first, so (f∘g)−1=g−1∘f−1(f \circ g)^{-1} = g^{-1} \circ f^{-1}. You'll assemble the proof in the last part of this chamber.

Learn: piecewise functions and the toolkit

Some functions follow different rules on different parts of the domain. Papers write them with a brace:

ReLU(x)={xif x>0,0otherwise.\mathrm{ReLU}(x) = \begin{cases} x & \text{if } x > 0, \\ 0 & \text{otherwise.} \end{cases}

Read it as “ReLU of x is x if x is positive, and 0 otherwise.” Each line gives a value and a condition, and exactly one condition applies to any input. A handful of small piecewise functions do a lot of work in ML papers:

The toolkit
  • {aif Pbotherwise\begin{cases} a & \text{if } P \\ b & \text{otherwise} \end{cases}“a if P, otherwise b”
    A piecewise definition. The brace lists the cases, and exactly one applies to each input.
  • ∣x∣|x|“the absolute value of x”
    The size of xx without its sign: xx if x≥0x \ge 0, and −x-x if x<0x < 0.
    ∣−3∣=3|-3| = 3
  • ⌊x⌋\lfloor x \rfloor“the floor of x”
    Round down to the nearest integer. Careful with negatives: ⌊−2.3⌋=−3\lfloor -2.3 \rfloor = -3.
    ⌊2.7⌋=2\lfloor 2.7 \rfloor = 2
  • ⌈x⌉\lceil x \rceil“the ceiling of x”
    Round up to the nearest integer.
    ⌈2.2⌉=3\lceil 2.2 \rceil = 3
  • max⁡(a,b)\max(a, b)“the max of a and b”
    The larger of the two numbers.
    ReLU(x)=max⁡(0,x)\mathrm{ReLU}(x) = \max(0, x)
  • min⁡(a,b)\min(a, b)“the min of a and b”
    The smaller of the two numbers.
    min⁡(3,−1)=−1\min(3, -1) = -1
  • 1[P]\mathbf{1}[P]“the indicator of P”
    1 if the statement PP is true, 0 if it's false. Also written 1P\mathbf{1}_{P}, I[P]\mathbb{I}[P] or with a double-struck one.
    1[y^=y]\mathbf{1}[\hat{y} = y]
  • δij\delta_{ij}“Kronecker delta i j”
    1 if i=ji = j and 0 otherwise: an indicator for “same index”.
    δ33=1, δ34=0\delta_{33} = 1,\ \delta_{34} = 0

A few of them in action:

  • ReLU(x)=max⁡(0,x)\mathrm{ReLU}(x) = \max(0, x), and ∣x∣=max⁡(x,−x)|x| = \max(x, -x).
  • A convolution with input width nn, kernel size kk, padding pp and stride ss produces ⌊n+2p−ks⌋+1\left\lfloor \frac{n + 2p - k}{s} \right\rfloor + 1 outputs. For n=28n = 28, k=5k = 5, p=0p = 0, s=2s = 2: ⌊23/2⌋+1=12\lfloor 23/2 \rfloor + 1 = 12.
  • Accuracy counts correct predictions with an indicator: example ii contributes 1[y^i=yi]\mathbf{1}[\hat{y}_i = y_i], which is 1 if the prediction is right and 0 if not. (Adding them up is Chamber 5's job.)
  • A one-hot label for class cc has entries yk=δkcy_k = \delta_{kc}: 1 in position cc, 0 everywhere else. The identity matrix of Chamber 6 has entries δij\delta_{ij} too.

Learn: exp and log

The number e=2.71828…e = 2.71828\ldots (Euler's number) is the natural base for growth and decay. The exponential function is x↦exx \mapsto e^{x}, also written exp⁡(x)\exp(x) when the exponent is long: exp⁡(−x2/2σ2)\exp(-x^2/2\sigma^2) is easier to read than e−x2/2σ2e^{-x^2/2\sigma^2}, with its tiny superscript. The logarithm is its inverse: log⁡(ex)=x\log(e^{x}) = x for every xx, and elog⁡y=ye^{\log y} = y for every y>0y > 0.

Which logarithm? In ML papers, log⁡\log without a base almost always means the natural log, base ee, which mathematicians also write ln⁡\ln. Information theory uses log⁡2\log_2, measured in bits. Python agrees with the papers: math.log and np.log are natural logs, and base 2 needs math.log2.

Every rule for logs is a rule for exponentials seen through the inverse:

ExponentialsLogarithms
ea+b=ea ebe^{a + b} = e^{a}\,e^{b}log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b
ea−b=ea/ebe^{a - b} = e^{a} / e^{b}log⁡ab=log⁡a−log⁡b\log\frac{a}{b} = \log a - \log b
(ea)k=eka(e^{a})^{k} = e^{ka}log⁡(ak)=klog⁡a\log(a^{k}) = k \log a
e0=1e^{0} = 1log⁡1=0\log 1 = 0

The log rules need a,b>0a, b > 0. To change base, divide: log⁡2x=log⁡xlog⁡2\log_2 x = \frac{\log x}{\log 2}.

A derivation: why logs turn products into sums

Let aa and bb be positive, and name their logs: u=log⁡au = \log a and v=log⁡bv = \log b. Because exp undoes log, a=eua = e^{u} and b=evb = e^{v}. Multiply, using the exponential rule:

ab=eu ev=eu+v.ab = e^{u}\,e^{v} = e^{u + v}.

Now take the log of both sides. Log undoes exp, so log⁡(ab)=u+v=log⁡a+log⁡b\log(ab) = u + v = \log a + \log b. The product rule for logs is the sum rule for exponentials, read backwards through the inverse.

That one rule explains why logs are everywhere in machine learning. Probabilities get multiplied, and a product of thousands of small numbers is too small for a computer to store. Its log is a harmless sum (Chamber 5). Logs also straighten power laws. If L=A/NαL = A / N^{\alpha}, then log⁡L=log⁡A−αlog⁡N\log L = \log A - \alpha \log N: a straight line when you plot log⁡L\log L against log⁡N\log N. That's why scaling-law papers draw log-log plots. Here is the most famous one's formula:

Spotted in the wild

L^(N,D)≜E+ANα+BDβ\hat{L}(N, D) \triangleq E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}
Hoffmann et al. (2022), “Training Compute-Optimal Large Language Models”, Eq. (2)

“L hat of N and D is defined as E, plus A over N to the alpha, plus B over D to the beta.” It's a function of two inputs, the model's parameter count NN and its number of training tokens DD, and the hat marks a prediction (Chamber 1). Its five constants EE, AA, BB, α\alpha and β\beta were fitted to over 400 training runs. You'll take it apart in the paper decoder and use it to make predictions in the coding problems.

Quick check +20 XP

For positive xx and yy, which expression equals log⁡(x3y)\log(x^3 y)?

Learn: activation functions are functions

Every activation function is a function R→R\mathbb{R} \to \mathbb{R}, applied to each entry of a vector. Read each one's contract and you know what it can output.

Activation functions
  • σ(z)\sigma(z)“sigma of z”
    The sigmoid 11+e−z\frac{1}{1 + e^{-z}}. It squashes any real number into (0,1)(0, 1), so its output can be read as a probability.
    σ(0)=12\sigma(0) = \tfrac{1}{2}
  • tanh⁡(z)\tanh(z)“tanh of z”
    The hyperbolic tangent: squashes into (−1,1)(-1, 1). It is a sigmoid, stretched and shifted: tanh⁡z=2σ(2z)−1\tanh z = 2\sigma(2z) - 1.
    tanh⁡(0)=0\tanh(0) = 0
  • ReLU(z)\mathrm{ReLU}(z)“relu of z”
    The rectified linear unit, max⁡(0,z)\max(0, z): negative inputs become 0, positive ones pass through.
    ReLU(−2)=0\mathrm{ReLU}(-2) = 0
  • softplus(z)\mathrm{softplus}(z)“softplus of z”
    log⁡(1+ez)\log(1 + e^{z}): a smooth version of ReLU that is always positive. The Deep Learning book writes it ζ(z)\zeta(z).
    softplus(0)=log⁡2\mathrm{softplus}(0) = \log 2
  • logit(p)\mathrm{logit}(p)“logit of p”
    The inverse of the sigmoid, log⁡p1−p\log\frac{p}{1-p}. The raw scores a classifier feeds to its sigmoid or softmax are called logits after it.
    logit(12)=0\mathrm{logit}\left(\tfrac{1}{2}\right) = 0
  • softmax(z)i\mathrm{softmax}(\mathbf{z})_i“softmax of z, entry i”
    A preview: turns a vector of scores into a vector of probabilities. The ∑\sum in its formula is Chamber 5's, and Chamber 9 decodes it in full.
    softmax(z)i=ezi∑jezj\mathrm{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}}

They're related by composition. The hyperbolic tangent is a sigmoid, stretched and shifted: tanh⁡z=2σ(2z)−1\tanh z = 2\sigma(2z) - 1, which is four machines in a row (double, σ\sigma, double, subtract 1). Softplus is log⁡∘(1+⋅)∘exp⁡\log \circ (1 + \cdot) \circ \exp. And the sigmoid's image, (0,1)(0, 1), is why its output can be read as a probability.

Research keeps inventing new ones, and the definitions are always short sentences in function notation. In 2017 a team at Google Brain used automated search to look for new activation functions, and highlighted this one:

Spotted in the wild

f(x)=x⋅σ(βx),σ(z)=(1+exp⁡(−z))−1f(x) = x \cdot \sigma(\beta x), \qquad \sigma(z) = (1 + \exp(-z))^{-1}
Ramachandran, Zoph & Le (2017), “Searching for Activation Functions”, Section 4

The paper calls it Swish, and adds that “β\beta is either a constant or a trainable parameter”. So strictly it's f(x;β)f(x; \beta), a family of functions. Look closely at the second formula: there the −1-1 is an ordinary power of a number, so (1+exp⁡(−z))−1(1 + \exp(-z))^{-1} means 11+exp⁡(−z)\frac{1}{1 + \exp(-z)}. Compare σ−1\sigma^{-1}, the inverse function you derived above. Same superscript, different meaning, and only the thing it's attached to tells you which.

A close cousin is GELU, defined by Hendrycks and Gimpel as xΦ(x)x\Phi(x), where Φ(x)\Phi(x) is the probability that a standard normal random variable (Chamber 8) comes out at most xx. They suggest the approximation xσ(1.702x)x\sigma(1.702x), which is Swish with β=1.702\beta = 1.702. Finally, a preview: softmax\mathrm{softmax} maps a whole vector of scores to a vector of probabilities, and its formula needs a sum over all entries. That's the notation of Chamber 5, and Chamber 9 decodes softmax in full.

DiscoverLearnRead beyondPapers & lecturesYour turn

Read beyond the course

Book · free online · ~40 min

Book of Proof

Richard Hammack · Chapter 12: Functions (§12.1, 12.2, 12.4 and 12.5)

A free, patient textbook on proofs. Chapter 12 defines functions, injective and surjective functions, composition and inverses with many small examples and exercises. Read it now to practise exactly the definitions this chamber used, one step more formally.

Book · free online · ~10 min

Deep Learning

Ian Goodfellow, Yoshua Bengio & Aaron Courville · Chapter 3, §3.10: Useful Properties of Common Functions

Two pages on the sigmoid and softplus, with a list of identities the authors suggest memorising, including the logit you derived and the softplus identity you'll prove below. Skip the rest of the chapter for now: it's probability, which is Chamber 8.

Article · free online · ~15 min

Demystifying the Natural Logarithm (ln)

Kalid Azad, BetterExplained

An intuitive essay on what ln⁡\ln measures: the time needed to grow to a certain amount. A good complement to this chamber's algebraic rules, and it explains why ee is the “natural” base.

Article · free online · ~25 min

Neural Networks, Manifolds, and Topology

Christopher Olah · Up to the end of “Topology of tanh Layers”

Animations of what each layer of a small network does to its input space, treating a layer as a composition of a matrix, a shift and an activation. It explains which layers are bijections (tanh and sigmoid layers can be, ReLU layers can't), so it's the injective and bijective ideas of this chamber, seen in pictures.

DiscoverLearnRead beyondPapers & lecturesYour turn

Papers and lectures

You can read both of this chamber's papers today, as long as you read selectively.

For ResNet, read Section 3.1 and Section 3.2. That's about one page. Section 3.1 is almost pure function notation: the authors call the mapping they want H(x)\mathcal{H}(\mathbf{x}) and define the residual as F(x):=H(x)−x\mathcal{F}(\mathbf{x}) := \mathcal{H}(\mathbf{x}) - \mathbf{x}. That's a definition with the :=:= of Chamber 1, so the original mapping becomes F(x)+x\mathcal{F}(\mathbf{x}) + \mathbf{x}. Then look at Figure 2, a picture of the block. Skip the architecture details and experiments, apart from Figure 1, which shows the problem the paper solves.

For Chinchilla, read the abstract, then Section 3.3, which introduces Eq. (2) in half a page. The fitted numbers are in Appendix D.2, Eq. (10). Skip the fitting procedure (Huber loss and L-BFGS are for later) and enjoy Figure 4, whose contours are level sets of the function L^\hat{L}.

Deep Residual Learning for Image RecognitionKaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun · CVPR, 2016

The paper that made very deep networks trainable, with one identity function added to every block. Residual connections are now in almost every large model, transformers included.

Training Compute-Optimal Large Language ModelsJordan Hoffmann, Sebastian Borgeaud, Arthur Mensch, et al. · NeurIPS, 2022

The Chinchilla paper. A two-input function fitted to over 400 training runs changed how labs split their compute between model size and data.

Decode the paper · Eq. (1), Section 3.2

Deep Residual Learning for Image Recognition

Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun · CVPR, 2016

+30 XP
y=F(x,{Wi})+x\mathbf{y} = \mathcal{F}(\mathbf{x}, \{W_i\}) + \mathbf{x}

The building block of every ResNet. The paper says: “Here x\mathbf{x} and y\mathbf{y} are the input and output vectors of the layers considered.” Match each piece to its job.

x\mathbf{x}
y\mathbf{y}
F\mathcal{F}
{Wi}\{W_i\}
+ x+\,\mathbf{x}

Options

Decode the paper · Eq. (2), Section 3.3

Training Compute-Optimal Large Language Models

Jordan Hoffmann, Sebastian Borgeaud, Arthur Mensch, et al. · NeurIPS, 2022

+30 XP
L^(N,D)≜E+ANα+BDβ\hat{L}(N, D) \triangleq E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}

The Chinchilla scaling law: a function of two inputs that predicts how good a language model will be before anyone trains it. Its five constants were fitted to the final losses of hundreds of training runs.

L^(N,D)\hat{L}(N, D)
≜\triangleq
NN
DD
EE
ANα\frac{A}{N^{\alpha}}
BDβ\frac{B}{D^{\beta}}

Options

Watch

Triangle of Power3Blue1Brown · 8 min

A short, playful argument that our notation for powers, roots and logarithms hides how closely they're related. Watch for how 23=82^3 = 8, 83=2\sqrt[3]{8} = 2 and log⁡28=3\log_2 8 = 3 describe one fact, and for the inverse pairs hiding in the triangle.

[Classic] Deep Residual Learning for Image Recognition (Paper Explained)Yannic Kilcher · 31 min

A walk through the ResNet paper. Watch for how he explains the residual block of Figure 2, and pause each time a formula appears to read it aloud before he does.

DiscoverLearnRead beyondPapers & lecturesYour turn

Your turn

Time to use it all. Translate between symbols, words and code, assemble one proof and write another, then solve three problems. Two of them use a paper's formula to make real predictions.

Match · Symbols ↔ Read aloud as

Say it aloud

+25 XP

Match each expression to the way a researcher would read it aloud.

f:R→Rf : \mathbb{R} \to \mathbb{R}
x↦x2x \mapsto x^2
(f∘g)(x)(f \circ g)(x)
f−1(y)f^{-1}(y)
f(x;θ)f(x; \theta)
⌊x⌋\lfloor x \rfloor
log⁡2x\log_2 x

Options

Match · Maths ↔ Python

From functions to Python

+25 XP

Match each piece of maths to the Python that computes it (with import math). Watch the logs: in Python, as in ML papers, a plain log is the natural log.

max⁡(0,x)\max(0, x)
⌊x⌋\lfloor x \rfloor
(f∘g)(x)(f \circ g)(x)
ln⁡x\ln x
log⁡2x\log_2 x
σ(z)\sigma(z)
1[x>0]\mathbf{1}[x > 0]

Options

Proofs

The first proof puts associativity to work: it's why socks come off before shoes. The second uses the log rules.

Proof puzzle

Socks and shoes

+25 XP

Claim

Let g:X→Yg : X \to Y and f:Y→Zf : Y \to Z have inverses g−1g^{-1} and f−1f^{-1}. Then f∘gf \circ g has an inverse, and

(f∘g)−1=g−1∘f−1.(f \circ g)^{-1} = g^{-1} \circ f^{-1}.

(Recall that h−1h^{-1} is the inverse of hh when h−1∘hh^{-1} \circ h and h∘h−1h \circ h^{-1} are both identity functions.)

Tap lines in the order they should appear. Not every line belongs. Tap a line in your proof to send it back.

Your proof

  1. Pick the first line below.

Available lines

Prove it yourself

Softplus minus its mirror image

+40 XP

Claim

The softplus function is ζ(x)=log⁡(1+ex)\zeta(x) = \log(1 + e^{x}), with the natural log. Prove that for every real number xx,

ζ(x)−ζ(−x)=x.\zeta(x) - \zeta(-x) = x.

(This is Eq. 3.41 of the Deep Learning book. It mirrors a fact about ReLU: max⁡(0,x)−max⁡(0,−x)=x\max(0, x) - \max(0, -x) = x.)

Preview

Your typeset proof appears here.

Code it up

The first problem undoes a composition. The other two take the Chinchilla formula at its word.

Problem 10·Warm-up

Undo two sigmoids

+20 XP

The sigmoid is σ(z)=11+e−z\sigma(z) = \dfrac{1}{1 + e^{-z}}. Find the real number xx with

(σ∘σ)(x)=σ(σ(x))=0.7.(\sigma \circ \sigma)(x) = \sigma(\sigma(x)) = 0.7.

Give xx rounded to 4 decimal places.

A number, rounded to 4 decimal places

Problem 11·Standard

Apply the paper: Chinchilla versus Gopher

+35 XP

The Chinchilla paper models the final training loss of a language model with NN parameters trained on DD tokens as

L^(N,D)=E+ANα+BDβ,\hat{L}(N, D) = E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}},

and fits the constants (Appendix D.2, Eq. 10): E=1.69E = 1.69, A=406.4A = 406.4, B=410.7B = 410.7, α=0.34\alpha = 0.34, β=0.28\beta = 0.28. Here NαN^{\alpha} is an ordinary power.

DeepMind's Gopher has N=280×109N = 280 \times 10^{9} parameters and was trained on D=300×109D = 300 \times 10^{9} tokens. Chinchilla has N=70×109N = 70 \times 10^{9} and D=1.4×1012D = 1.4 \times 10^{12}: a model four times smaller, trained on almost five times more data.

Compute L^(Gopher)−L^(Chinchilla)\hat{L}(\text{Gopher}) - \hat{L}(\text{Chinchilla}), rounded to 4 decimal places.

A number, rounded to 4 decimal places

Problem 12·Challenge

Apply the paper: spend a compute budget

+50 XP

Training a model with NN parameters on DD tokens costs about C=6NDC = 6ND floating-point operations (FLOPs), the approximation the Chinchilla paper uses. Fix the budget at Gopher's, C=5.76×1023C = 5.76 \times 10^{23} FLOPs. Then the number of tokens you can afford is a function of the model size, D(N)=C6ND(N) = \frac{C}{6N}, and the predicted loss becomes a function of one variable, a composition:

ℓ(N)=L^(N,D(N)),L^(N,D)=E+ANα+BDβ,\ell(N) = \hat{L}\big(N, D(N)\big), \qquad \hat{L}(N, D) = E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}},

with the paper's fitted constants E=1.69E = 1.69, A=406.4A = 406.4, B=410.7B = 410.7, α=0.34\alpha = 0.34, β=0.28\beta = 0.28.

Consider model sizes that are whole numbers of billions: N=k×109N = k \times 10^{9} for k=1,2,…,500k = 1, 2, \ldots, 500. For which kk is ℓ(N)\ell(N) smallest? Answer with the integer kk.

An exact integer (or a fraction like 7/12)

Key takeaways

  • Read the contract first. f:X→Yf : X \to Y names the domain and codomain; x↦f(x)x \mapsto f(x) gives the rule; the image is what ff actually produces.
  • Parameters sit after the semicolon (or in the subscript): f(x;θ)f(\mathbf{x}; \theta) and fθ(x)f_\theta(\mathbf{x}) are a family of functions, one for each θ\theta.
  • Composition reads right to left. (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)) applies gg first. It's associative but not commutative, and a deep network is one long composition.
  • f−1f^{-1} undoes ff and is not 1/f1/f. Only bijections have inverses, and (f∘g)−1=g−1∘f−1(f \circ g)^{-1} = g^{-1} \circ f^{-1}.
  • exp and log are inverses. Logs turn products into sums and power laws into straight lines, and a plain log⁡\log in a paper is the natural log.
  • Activations, residual blocks and scaling laws are all functions: σ\sigma, tanh⁡\tanh, ReLU\mathrm{ReLU}, x↦x+F(x)\mathbf{x} \mapsto \mathbf{x} + \mathcal{F}(\mathbf{x}) and L^(N,D)\hat{L}(N, D).

Checkpoint

Prove it to the labyrinth

Answer every question to clear this chamber. First-try answers earn the most XP.

0/8
Question 1 of 8 +20 XP

A paper writes its model as f(x;θ)f(\mathbf{x}; \theta). What does the semicolon tell you?

Question 2 of 8 +20 XP

Let f(x)=3x−2f(x) = 3x - 2. What is f−1(10)f^{-1}(10)?

Question 3 of 8 +20 XP

Compute ⌊−2.3⌋+⌈−2.3⌉\lfloor -2.3 \rfloor + \lceil -2.3 \rceil.

Question 4 of 8 +20 XP

Let f(x)=⌊x/3⌋f(x) = \lfloor x/3 \rfloor, g(x)=∣x−10∣g(x) = |x - 10| and h(x)=max⁡(0,x)h(x) = \max(0, x). What is (f∘g∘h)(−4)(f \circ g \circ h)(-4)?

Question 5 of 8 +20 XP

The GELU paper writes the ReLU as x1x>0x\mathbf{1}_{x>0}. What does that expression mean?

Question 6 of 8 +20 XP

Which of these functions has an inverse, taking its image as the codomain?

Question 7 of 8 +20 XP

In Chinchilla's L^(N,D)≜E+ANα+BDβ\hat{L}(N, D) \triangleq E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}, with A,B,α,βA, B, \alpha, \beta all positive, what happens to the predicted loss as both NN and DD grow without bound?

Question 8 of 8 +20 XP

Two residual blocks, h1(x)=x+F1(x)h_1(\mathbf{x}) = \mathbf{x} + \mathcal{F}_1(\mathbf{x}) and h2(x)=x+F2(x)h_2(\mathbf{x}) = \mathbf{x} + \mathcal{F}_2(\mathbf{x}), are stacked with h1h_1 first. Which expression is (h2∘h1)(x)(h_2 \circ h_1)(\mathbf{x})?

End of the chamber

Clear this chamber

+50 XPFunctionCompositionInverse FunctionExp and Log