Stable softmax and log-softmax
Convert logits to probabilities, log probabilities and a stable log normalizer.
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
{"logits":[1000,1001,1002]}{"probabilities":[0.090031,0.244728,0.665241],"log_probabilities":[-2.407606,-1.407606,-0.407606],"log_normalizer":1002.407606}{"logits":[7]}{"probabilities":[1],"log_probabilities":[0],"log_normalizer":7}{"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.
Read the report, then sign in to start your investigation.