Command Palette

Search for a command to run...

Hectal
Phase 1: How LLMs Work (for Engineers)
LLM Engineering · Exercise 3 of 5 PreviousNext
Beginner

Softmax with temperature

Write softmax_t(logits, t) that returns a list of probabilities: divide each logit by t, subtract the largest value for stability, apply exp, and divide by the total.

If t is 0, behave like greedy decoding: return a list with 1.0 at the position of the largest logit (the first one on a tie) and 0.0 elsewhere.

What Check tests

  1. Probabilities add up to 1
  2. [2, 1, 0] at T=1 gives 0.6652, 0.2447, 0.09
  3. A lower temperature makes the top token more likely
  4. Temperature 0 is greedy
  5. Large logits do not overflow

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.