bugger.
All challenges/Pythonhardllm-encoder-decoder-v1
THE INVESTIGATION

Build encoder and cross-attention paths

Assemble a bidirectional encoder and a causal decoder with cross-attention.

LLM ArchitectureArchitecture builds

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 source and target are nonempty width-D embedded token rows, source_mask selects valid source keys, and encoder, decoder and cross each provide q, k, v and out projections. Encoder: add bidirectional projected source self-attention to source rows, using source_mask for keys. Decoder: add projected causal target self-attention to target rows; then add projected cross-attention with decoder rows as queries and encoder rows as KV, using source_mask for source keys. Output encoded and decoded states. No norms, dropout or FFNs in this exercise.

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

Assemble a bidirectional encoder and a causal decoder with cross-attention.

Reproduction

01 Source and target have different sequence lengths
{"source":[[1,0],[0,1],[1,1]],"target":[[0,1],[1,0]],"source_mask":[true,true,true],"encoder":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"decoder":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"cross":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]}}
{"encoded":[[1.802224,0.598888],[0.598888,1.802224],[1.751745,1.751745]],"decoded":[[1.210617,3.676155],[3.296831,1.636753]]}
02 Zero output projections give identity
{"source":[[1,0]],"target":[[0,1]],"source_mask":[true],"encoder":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[0,0],[0,0]]},"decoder":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[0,0],[0,0]]},"cross":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[0,0],[0,0]]}}
{"encoded":[[1,0]],"decoded":[[0,1]]}
03 Masked source cannot supply values
{"source":[[10,10],[0,1]],"target":[[1,1]],"source_mask":[false,true],"encoder":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"decoder":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]},"cross":{"q":[[1,0],[0,1]],"k":[[1,0],[0,1]],"v":[[1,0],[0,1]],"out":[[1,0],[0,1]]}}
{"encoded":[[10,11],[0,2]],"decoded":[[2,4]]}

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.