This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python softmax and temperature, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
What does a softmax distribution sum to?
Answer: 1
Why: Softmax normalizes every exponentiated logit by the total, so the probabilities sum to one.
Why subtract the maximum logit before exp?
Answer: To avoid numerical overflow without changing the ratios
Why: Shifting every logit by the same constant leaves the softmax ratios unchanged and keeps exp in range.
What does a lower temperature do?
Answer: Makes the distribution sharper
Why: Dividing logits by a smaller positive temperature increases the gap between high and low scores.
What is the output?
import math
def softmax(logits):
largest = max(logits)
exps = [math.exp(x - largest) for x in logits]
total = sum(exps)
return [x / total for x in exps]
print([round(p, 2) for p in softmax([0, 0])])Answer: [0.5, 0.5]
Why: Equal logits receive equal probability, and the two values sum to one.
Complete the stable shift inside softmax.
import math
logits = [1000, 1000]
largest = max(logits)
exps = [math.exp(x - ____) for x in logits]
total = sum(exps)
print([round(x / total, 2) for x in exps])Answer: largest
Why: Subtracting the largest logit keeps the exponentials from overflowing.
Complete the normalization denominator.
import math
logits = [2, 0]
largest = max(logits)
exps = [math.exp(x - largest) for x in logits]
total = sum(exps)
print([round(x / ____, 3) for x in exps])Answer: total
Why: Every exponentiated value is divided by the sum of all exponentiated values.
Complete the temperature scaling step.
import math
logits = [2, 0]
temperature = 2.0
scaled = [x / ____ for x in logits]
largest = max(scaled)
exps = [math.exp(x - largest) for x in scaled]
total = sum(exps)
print([round(x / total, 3) for x in exps])Answer: temperature
Why: Temperature divides the logits before the stable softmax is computed.
Complete the key function that selects the largest probability.
probs = [0.2, 0.8]
winner = max(range(len(probs)), key=probs.____)
print(winner)Answer: __getitem__
Why: probs.__getitem__ lets max compare the probabilities by index.
What does this code print?
import math
def softmax(logits):
largest = max(logits)
exps = [math.exp(x - largest) for x in logits]
total = sum(exps)
return [x / total for x in exps]
print([round(p, 3) for p in softmax([0, 0])])Answer: [0.5, 0.5]
Why: Equal logits produce equal probabilities that sum to one.
What does the program output?
import math
def softmax(logits):
largest = max(logits)
exps = [math.exp(x - largest) for x in logits]
total = sum(exps)
return [x / total for x in exps]
print([round(p, 3) for p in softmax([2, 0])])Answer: [0.881, 0.119]
Why: The larger logit gets most of the mass: about 0.881 versus 0.119.
What appears on the screen?
import math
def softmax(logits, temperature):
scaled = [x / temperature for x in logits]
largest = max(scaled)
exps = [math.exp(x - largest) for x in scaled]
total = sum(exps)
return [x / total for x in exps]
print([round(p, 3) for p in softmax([2, 0], 2.0)])Answer: [0.731, 0.269]
Why: A higher temperature flattens the distribution to about 0.731 and 0.269.
What is printed?
probs = [0.7, 0.2, 0.1]
print(round(sum(probs), 3))Answer: 1.0
Why: The probabilities sum to 1.0.
Try the questions first
Open the practice page for Python softmax and temperature and answer the same 12 questions with instant feedback.