bugger.
All challenges/Pythoneasyllm-stable-softmax-v1
THE INVESTIGATION

Stable softmax and log-softmax

Convert logits to probabilities, log probabilities and a stable log normalizer.

LLM ArchitectureML foundations

What’s going wrong

Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.

Input logits is a nonempty list of finite scores with absolute value at most 10,000. Return probabilities, log_probabilities and log_normalizer. Keep log probabilities finite even where exp underflows. Preserve input order.

Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.

Expected behavior

Convert logits to probabilities, log probabilities and a stable log normalizer.

Reproduction

01 Large common offset
{"logits":[1000,1001,1002]}
{"probabilities":[0.090031,0.244728,0.665241],"log_probabilities":[-2.407606,-1.407606,-0.407606],"log_normalizer":1002.407606}
02 One possible token
{"logits":[7]}
{"probabilities":[1],"log_probabilities":[0],"log_normalizer":7}
03 Equal logits
{"logits":[-3,-3]}
{"probabilities":[0.5,0.5],"log_probabilities":[-0.693147,-0.693147],"log_normalizer":-2.306853}

Before you begin

  • Python functions, lists and dictionaries

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.