All problems
EasyNeural Networks & LLM Componentsv2026-06-27

Neural Networks & LLM Components ยท Easy

Stable Softmax

Convert logits into probabilities without overflow or underflow.

Task

Implement stable_softmax(logits: list[float]) -> list[float]. Convert a one-dimensional sequence of logits into probabilities using the numerically stable softmax transformation.

Requirements

  • Subtract the maximum logit before exponentiation.
  • Return probabilities in the original input order.
  • Return an empty result of the selected implementation type for empty input.
  • The returned probabilities must sum to 1.0 for non-empty input.

Example

logits = [1.0, 2.0, 3.0]

stable_softmax(logits)
# [0.09003057, 0.24472847, 0.66524096]
solution.pySign in to save
Public tests run locally in your browser.
Run your code to see public test results.