Trigonometry & Position Fingerprints
P2.math-foundations.08 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Gradients & Optimisation Intuition
Where next?
This module unlocks
P2.math-foundations.08 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Gradients & Optimisation Intuition
This module unlocks
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.
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.
This series recalls Probability & Statistics Basics, Exponentials, Logarithms & Softmax, Gradients & Optimisation Intuition and Trigonometry & Position Fingerprints, and brings back two ideas from series 1.
Self-check
Which statement must hold for any probability distribution over the words of a vocabulary?
Self-check
Which function undoes e to the power x, so that applying both returns the original number?
Self-check
In gradient descent, what does the learning rate control?
Self-check
A point sits on the circle of radius 1 at an angle of 90 degrees, straight above the centre. What is the cosine of that angle? Give a whole number.
Self-check
Four test scores are 2, 4, 6 and 8. What is their variance, taken as the average squared distance from the mean? Give a whole number.
Self-check
Softmax is applied to the three scores 1, 1 and 1. What comes out?
Self-check
Two word vectors are (2, 1) and (1, 3). What is their dot product? Give a whole number.
Self-check
Lea's training error jumps up and down and never settles, so she doubles the learning rate to speed things up. What is the flaw?
Self-check
Tom says the sine-based position value for word 300 of a long text can reach 3. What is wrong?
Self-check
A student types 0.1 + 0.2 into Python, sees 0.30000000000000004, and concludes the computer is broken. What is the better explanation?
Practise this lesson's 10 self-checks
One per screen: 10 checked on this page, 0 you reveal and mark yourself. Nothing is recorded.
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.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
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.
Loading your notes...