PIXELBANKv9.1.0
Menu

Implement temperature-scaled sampling from logits.

Temperature controls the randomness of predictions:

  1. Divide logits by temperature T
  2. Apply softmax: pi=ezi/T∑jezj/Tp_i = \frac{e^{z_i/T}}{\sum_j e^{z_j/T}}

Higher T -> more uniform (random), lower T -> more peaked (deterministic).

Since we need deterministic output for testing, instead of sampling, return the probability distribution after temperature scaling.

Input format:

  • Line 1: Temperature T (float)
  • Line 2: Space-separated logits (floats)

Output: The probability distribution after temperature scaling, as a list of floats rounded to 4 decimal places.

Example:

Input:
1.0
2.0 1.0 0.1
Output:
[0.6590, 0.2424, 0.0986]
Reasoning:

Temperature = 1.0 (standard softmax): Logits / T = [2.0, 1.0, 0.1] Subtract max: [0.0, -1.0, -1.9] exp: [1.0, 0.3679, 0.1496] Sum = 1.5175 Probabilities: [1.0/1.5175, 0.3679/1.5175, 0.1496/1.5175] = [0.6590, 0.2424, 0.0986]

Constraints:

  • T > 0
  • Use softmax with numerical stability (subtract max)
  • Round each probability to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.