bugger.
All challenges/Pythoneasyllm-cross-entropy-v1
THE INVESTIGATION

Cross-entropy from logits

Compute mean cross-entropy and its gradient with respect to each logit.

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 batch of equally sized nonempty score rows. targets contains class IDs or -1 to ignore a row. Return loss and gradient with the original batch shape. Average over valid rows. Return zero loss and zero gradients when every row is ignored.

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

Compute mean cross-entropy and its gradient with respect to each logit.

Reproduction

01 Extreme wrong prediction
{"logits":[[1000,-1000]],"targets":[1]}
{"loss":2000,"gradient":[[1,-1]]}
02 Ignored batch
{"logits":[[2,4]],"targets":[-1]}
{"loss":0,"gradient":[[0,0]]}
03 One class gives zero loss
{"logits":[[3]],"targets":[0]}
{"loss":0,"gradient":[[0]]}

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.