Loading...
Given a list of logits (raw scores) for vocabulary words and a temperature value, apply temperature scaling and compute the resulting probability distribution using softmax.
Temperature scaling divides each logit by the temperature before applying softmax: pi=∑jezj/Tezi/T
Input format:
Output: Each word and its probability (rounded to 4 decimal places), sorted by probability descending, one per line as "word probability".
cat:2.0,dog:1.0,fish:0.5 1.0
cat 0.6285 dog 0.2312 fish 0.1402
Step 1: Divide logits by temperature (T=1.0) cat: 2.0/1.0 = 2.0, dog: 1.0/1.0 = 1.0, fish: 0.5/1.0 = 0.5
Step 2: Apply softmax e^2.0 ≈ 7.389, e^1.0 ≈ 2.718, e^0.5 ≈ 1.649 Sum ≈ 11.756
Step 3: Normalize cat: 7.389/11.756 ≈ 0.6285 dog: 2.718/11.756 ≈ 0.2312 fish: 1.649/11.756 ≈ 0.1402