Cross-entropy from logits
Compute mean cross-entropy and its gradient with respect to each logit.
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
{"logits":[[1000,-1000]],"targets":[1]}{"loss":2000,"gradient":[[1,-1]]}{"logits":[[2,4]],"targets":[-1]}{"loss":0,"gradient":[[0,0]]}{"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.
Read the report, then sign in to start your investigation.