Exponentials, Logarithms & Softmax
P2.math-foundations.06 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Probability & Statistics Basics
Where next?
Later in Mathematics Foundations
P2.math-foundations.06 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Probability & Statistics Basics
Later in Mathematics Foundations
The exponential function e^x has two properties that make it the beating heart of a Transformer: it is always positive and it grows extremely fast. Those two facts are exactly what you need to turn a list of raw attention scores — some positive, some negative — into a set of probabilities that sum to 1. This module builds e ≈ 2.718 from scratch, meets its inverse the natural logarithm ln(x), and then assembles softmax step by step on our four-sentence demo corpus.
A power such as 2³ simply means "multiply 2 by itself three times" (2 × 2 × 2 = 8). Euler's number e ≈ 2.71828 is a special number that appears whenever something grows continuously — the way money grows under continuous compound interest. Imagine 1 euro earning 100 % interest, but paid out in ever-smaller slices more and more often: the year-end value creeps up toward e and never past it.
Why it matters — Softmax uses e^x because e^x is always greater than zero (so it turns even negative scores into positive weights), and because dividing each e^x by the total of all of them always yields a clean set of probabilities that sum to 1.
The table below shows the compounding value (1 + 1/n) raised to the power n creeping up toward e as the slices n get finer.
| Slices per year (n) | Year-end value (1 + 1/n) raised to n |
|---|---|
| 1 | 2.00000 |
| 12 (monthly) | 2.61304 |
| 365 (daily) | 2.71457 |
| 1 000 000 | 2.71828 |
| infinitely many | 2.71828… = e |
Interview-grade notes for the technical (it-ml) track.
Temperature rescales the logits before softmax: softmax(z / T).
Attention entropy. Each head produces a softmax distribution over positions; its entropy measures how spread out the attention is (low = sharp focus, high = diffuse). Monitoring per-head attention entropy during training diagnoses head collapse — heads degenerating to uniform, or fixating on a single attention-sink token — and flags instability. It is a genuinely useful diagnostic.
Sampling for generation (decoding-time, same softmax):
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...