PIXELBANKv9.1.0
Menu

Implement temperature scaling for language model logits.

Temperature controls the randomness of sampling by scaling logits before softmax: P(i)=ezi/T∑jezj/TP(i) = \frac{e^{z_i / T}}{\sum_j e^{z_j / T}}

Higher T → more uniform (creative), lower T → more peaked (deterministic).

Input:

  • Line 1: temperature T
  • Line 2: space-separated logits

Output: Probability distribution after temperature scaling, rounded to 4 decimal places.

Example:

Input:
1.0
2.0 1.0 0.1
Output:
0.6590 0.2424 0.0986
Reasoning:
  • The temperature TT is given as 1.0, which means the logits will be scaled by this value.
  • The logits ziz_i are given as 2.0, 1.0, and 0.1, and we calculate the scaled logits: zi/T=2.0/1.0=2.0z_i / T = 2.0 / 1.0 = 2.0, 1.0/1.0=1.01.0 / 1.0 = 1.0, and 0.1/1.0=0.10.1 / 1.0 = 0.1.
  • We then apply the softmax function: P(i)=ezi/T∑jezj/T=e2.0e2.0+e1.0+e0.1P(i) = \frac{e^{z_i / T}}{\sum_j e^{z_j / T}} = \frac{e^{2.0}}{e^{2.0} + e^{1.0} + e^{0.1}}, P(i)=e1.0e2.0+e1.0+e0.1P(i) = \frac{e^{1.0}}{e^{2.0} + e^{1.0} + e^{0.1}}, and P(i)=e0.1e2.0+e1.0+e0.1P(i) = \frac{e^{0.1}}{e^{2.0} + e^{1.0} + e^{0.1}}.
  • Calculating these values gives us the probabilities: P(1)≈0.6590P(1) \approx 0.6590, P(2)≈0.2424P(2) \approx 0.2424, and P(3)≈0.0986P(3) \approx 0.0986.

Constraints:

  • T > 0
  • Use numerically stable softmax (subtract max)
  • Round to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.
Temperature Sampling - Easy | PixelBank