InferenceAI

Enter at least two characters to search.

Start free

Stable Softmax

mediumTensors20 min25 XP

Return numerically stable softmax probabilities rounded to six decimals.

INTERACTIVE CONCEPT

See scores become probabilities

Adjust one logit to see how softmax redistributes probability across three values.

Logit 1: 0.0
42.2%
Logit 2: 0.0
42.2%
Logit 3: -1.0
15.5%

Subtracting the largest logit before exponentiation preserves the probabilities while reducing overflow risk.

Examples

EXAMPLE WALKTHROUGHequal

A guided view of the published example, not a trace of your code.

INPUT[[0,0]]
TASKstable_softmax()
EXPECTED OUTPUT[0.5,0.5]

Start with the input values shown in this example.

Example 1 of 2

Input: logits = [0,0]

Output: [0.5,0.5]

Explanation: equal

Input: logits = [1000,1000]

Output: [0.5,0.5]

Explanation: large logits

Hint 1

Subtract the maximum logit before exponentiation.

Topics

PythonTensors