Trigonometry & Position Fingerprints
P2.math-foundations.08 · Audience: guest, it-ml, language-pro · Prerequisites: Gradients & Optimisation Intuition
Sine and cosine are smooth, repeating waves that never rise above 1 or fall below −1. They are the mathematical way to describe any regular, cyclic pattern — the rise and fall of intonation in a spoken sentence, the alternation of seasons, the beat of a rhythm. This module builds the intuition slowly, with no prior maths, and it leads directly to the P10 Positional Encoding track: a Transformer reads every word in a sentence at once, so it needs a way to tag each word with where it sits. It does this by combining these waves at many speeds to give every position a unique numerical fingerprint.
Picture a circle drawn around a centre point, with a radius of exactly 1. Now pick a spot on the edge of that circle by turning through some angle. Sine and cosine are simply the two coordinates of that spot: cosine is how far right or left it sits, and sine is how far up or down it sits. Because the circle has radius 1, neither value can ever be bigger than 1 or smaller than −1 — the spot never leaves the circle.
🗣️ From a linguist's perspective: Cyclic patterns — language as a repeating signal
ⓘ Concept: The unit circle — radius = 1
Why it matters — The Transformer's positional encoding applies sine and cosine to a word's position. Because their output always stays between −1 and 1, the position information never overwhelms the word's own meaning values, which are also small numbers.
As you turn around the circle, the two coordinates take on familiar landmark values. The table below shows a few key turning points, from the start all the way around to one full rotation.
| Angle turned | Spot on the circle | cosine (across) | sine (up) |
|---|---|---|---|
| start (0) | far right | 1 | 0 |
| quarter turn | top | 0 | 1 |
| half turn | far left | −1 | 0 |
| full turn | back to far right | 1 | 0 |
At a 45-degree turn — halfway between the start and the top — sine and cosine happen to share the same value, about 0.707 each. One full turn brings you right back to where you began, which is what makes these waves repeat.
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.
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.