Dispatch experts through a latent projection
Implement a latent mixture-of-experts block with a wide residual.
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.
down maps D features into L, router maps L into E scores, and experts contains E latent L×L matrices. For each token compute latent = x·down, select k experts by descending scores with ties by ID, then take their stable softmax-weighted mixture in latent space. Project via up (L×D) and add the original token. Return selected and output. Use simple linear experts 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
Implement a latent mixture-of-experts block with a wide residual.
Reproduction
{"x":[[1,2,5]],"down":[[1],[2],[0]],"router":[[2,-1,1]],"experts":[[[1]],[[3]],[[-1]]],"up":[[2,0,-1]],"k":1}{"selected":[[0]],"output":[[11,2,0]]}{"x":[],"down":[[1],[2],[0]],"router":[[2,-1,1]],"experts":[[[1]],[[3]],[[-1]]],"up":[[2,0,-1]],"k":2}{"selected":[],"output":[]}{"x":[[0,1,0]],"down":[[1],[2],[0]],"router":[[2,-1,1]],"experts":[[[1]],[[3]],[[-1]]],"up":[[2,0,-1]],"k":2}{"selected":[[0,2]],"output":[[3.046377,1,-1.523188]]}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.