bugger.
All challenges/Pythoneasyllm-embedding-lookup-v1
THE INVESTIGATION

Token embeddings and shared-row gradients

Implement embedding lookup and scatter-add its gradients.

LLM ArchitectureTokenization

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_ids are valid row IDs in a nonempty weights matrix. gradient contains one upstream row per token position. padding_id is null or a reserved row. Output vectors with one row per input token and grad_weights with one row per vocabulary item. Padding outputs zeros and contributes zero gradient.

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

Implement embedding lookup and scatter-add its gradients.

Reproduction

01 Repeated token sums distinct contributions
{"weights":[[2,3],[4,5],[6,7]],"input_ids":[1,1],"gradient":[[1,2],[3,4]],"padding_id":null}
{"vectors":[[4,5],[4,5]],"grad_weights":[[0,0],[4,6],[0,0]]}
02 No input tokens
{"weights":[[2,3],[4,5],[6,7]],"input_ids":[],"gradient":[],"padding_id":null}
{"vectors":[],"grad_weights":[[0,0],[0,0],[0,0]]}
03 Reserved padding masks a nonzero row
{"weights":[[2,3],[4,5],[6,7]],"input_ids":[0,2],"gradient":[[99,99],[2,3]],"padding_id":0}
{"vectors":[[0,0],[6,7]],"grad_weights":[[0,0],[0,0],[2,3]]}

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.