Functions & Graphs

P2.math-foundations.02 · Audience: guest, it-ml, language-pro · Prerequisites: Numbers & Computer Representations

A function is simply a rule that turns one number into another: you give it an input, it gives back an output. That is the whole idea, and it is the single most important tool in this tutorial. Every transformation inside a Transformer — the embedding lookup, attention, the feed-forward layer — is a function, and a small family of special functions (ReLU, sigmoid, tanh, softmax) shapes numbers at every layer. This module explains what functions are, how we picture them as graphs, and how chaining them together builds the entire model.

Step 1 / 5What Is a Function?

A function is a rule that turns one number (or set of numbers) into another. You give it an input, it hands back an output. That is all it is. You already use functions every day:

  • A currency converter: input € 100 gives output $ 108.
  • A thermometer: input 37 °C gives output 98.6 °F (rule: F = C × 9/5 + 32).
  • A spell-checker: input a misspelled word gives output a corrected word.

In mathematics we write f(x) = some rule. The letter x is the input; f(x) is the output.

🗣️ From a linguist's perspective: Functions as rules that map inputs to outputs — like grammatical rules
A grammatical rule is a function: it maps an input (a verb stem) to an output (an inflected form). walk plus the past-tense rule gives walked; go plus the past-tense rule gives went — an irregular output, but still a deterministic mapping for a given word. A mathematical function is the same idea extended to numbers: a rule that maps every input to exactly one output. The Transformer is built from chains of such functions — each layer takes a table of numbers as input and produces a new table as output, following a deterministic rule encoded in its learned weights.
ⓘ Concept: Functions — the core idea
A function f maps each input x to exactly one output f(x). We write it as f : X → Y, where X is the domain (all allowed inputs) and Y is the codomain (all possible outputs). For example, f(x) = x² maps every real number to a non-negative number.
f:RR,f(x)=x2f : \mathbb{R} \to \mathbb{R}, \quad f(x) = x^2

Why it matters — Every transformation inside the Transformer is a function. The embedding lookup, the dot-product attention, the feed-forward layer — each is a function that takes a vector as input and returns a vector as output.

Three everyday functions, side by side over inputs from −3 to 3: f(x) = x² (a bowl-shaped curve), g(x) = 2x + 1 (a straight line), and h(x) = the absolute value of x (a V-shape). Each takes the same input and produces its own output.

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.

Ctrl/Cmd + Enter to send

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.