Answer key · 12 questions

Python softmax and temperature Exercises With Answers

All 12 questions for Python softmax and temperature in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

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.

01 · Multiple choice

What does a softmax distribution sum to?

  1. The largest logit
  2. 1correct
  3. 0
  4. The number of classes

Answer: 1

Why: Softmax normalizes every exponentiated logit by the total, so the probabilities sum to one.

02 · Multiple choice

Why subtract the maximum logit before exp?

  1. To make the answer more accurate than the model
  2. To avoid numerical overflow without changing the ratioscorrect
  3. To remove negative classes
  4. To make all probabilities equal

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.

03 · Multiple choice

What does a lower temperature do?

  1. Changes the number of classes
  2. Makes every probability equal
  3. Makes the distribution sharpercorrect
  4. Removes the need for normalization

Answer: Makes the distribution sharper

Why: Dividing logits by a smaller positive temperature increases the gap between high and low scores.

04 · Multiple choice

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])])
  1. [0.25, 0.75]
  2. [0.0, 0.0]
  3. [1.0, 1.0]
  4. [0.5, 0.5]correct

Answer: [0.5, 0.5]

Why: Equal logits receive equal probability, and the two values sum to one.

05 · Fill in the blank

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.

06 · Fill in the blank

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.

07 · Fill in the blank

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.

08 · Fill in the blank

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.

09 · Predict output

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.

10 · Predict output

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.

11 · Predict output

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.

12 · Predict output

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.

Practice this lesson