Rotary position embeddings (RoPE)
Rotate each adjacent feature pair using its own frequency and absolute token position.
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 rows are token vectors of even dimension d, positions gives nonnegative position IDs, base is positive and output shape matches rows. For pair i, rotate (x,y) by angle position × base^(−2i/d) using (x*cos − y*sin, x*sin + y*cos). Preserve order and support empty rows input.
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
Rotate each adjacent feature pair using its own frequency and absolute token position.
Reproduction
{"rows":[[1,0,1,0]],"positions":[3],"base":100}[[-0.989992,0.14112,0.955336,0.29552]]
{"rows":[[1,2,3,4]],"positions":[0],"base":10000}[[1,2,3,4]]
{"rows":[[1,0],[1,0]],"positions":[2,4],"base":10000}[[-0.416147,0.909297],[-0.653644,-0.756802]]
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.