Module 0 · optional · Lesson 0.1

The grammar of mathematical notation

Read a declaration as a sentence before trying to calculate. By the end, you should distinguish an object's type and shape from an operation that changes it.

Prerequisite: arrays with rows and columns; ordinary multiplication. No other toolkit lesson is required.

0.1.1 A declaration names the object

In attention, the incoming token representations form a matrix. Read the following aloud: “X is a real-valued matrix with T rows and d-model columns.” This is a declaration rather than a computation.

X ∈ ℝ^(T × d_model)

X
Incoming token-representation matrix.
∈
“Belongs to” the set or type on the right.
ℝ
The real numbers.
T × d_model
Shape: sequence length by model width, with one token per row.

For the invented phrase “The sky is”, let the sequence length be 3 and model width be 4. Then X contains 3 rows, 4 columns and 12 numbers. The declaration does not supply those numbers or ask you to multiply two matrices. Real implementations store finite-precision approximations to real numbers.

0.1.2 Read the marks by their role

A compact reading key
ExpressionRead it as
x_iThe entry at index i in vector x; the subscript selects a component.
x²The square of x; this superscript is a power.
KᵀThe transpose of key matrix K; this superscript swaps rows and columns.
y = f(x)Apply function f to input x to obtain output y.
r := (a+b)/cDefine r as the sum of a and b divided by nonzero c. The fraction groups the entire numerator.
1/3 ≈ 0.333The decimal is an approximation; equality would claim exactly the same value.

The equality sign states that two values are equal; it does not mean “execute the next instruction” as an assignment might in code. The definition sign introduces a name. A function's domain is its allowed input set: for real-valued square root, the input must be nonnegative.

Context resolves overload. T in a shape denotes sequence length. The upright superscript T on K means transpose, not “raise K to the sequence length.” Likewise, a subscript can name a role: W with subscript Q names a query-projection matrix; it does not necessarily select the Q-th entry.

0.1.3 Worked example: declaration and operation

Consider an invented key matrix with 3 token rows and 2 key components per token:

K is 3 by 2: rows [1,2], [3,4], [5,6]. Its transpose has rows [1,3,5] and [2,4,6].

The first expression declares a shape. The middle expression gives the entries. The last expression performs a transpose: the first column becomes the first row. No entry is squared or discarded; six entries remain, arranged as 2 rows and 3 columns.

Common mistake: treating every superscript as a power. Check the convention and the object's type before calculating. A square matrix can have both a power and a transpose, but these are different operations.

0.1.4 Decode before seeing help

First predict whether the displayed statement describes a type, selects an entry, or transforms an object. Reveal hints only if you need them; then try again with the hints closed.

0.1.5 Transfer without a diagram

Cover the examples above. Given U ∈ ℝ^(5 × 3), explain what is known and unknown. What shape does Uᵀ have? Does the declaration tell you the value of U₂,₁?

Check the reference explanation

U has 5 rows and 3 columns, with real-valued entries. Its 15 values remain unknown. Its transpose has 3 rows and 5 columns. U with subscript 2,1 selects row 2, column 1 under this lesson's one-based indexing convention; the declaration alone cannot give its value. If you answered “15” for the entry, you counted elements rather than reading one.

Now write your own declaration for a real matrix with 7 token rows and 4 features. A valid reference is E ∈ ℝ^(7 × 4); the choice of matrix name is arbitrary.

See these declarations in the attention projections.

Return to the attention equation