| { |
| "task": { |
| "id": "case_103", |
| "name": "swap_consecutive", |
| "summary": "Swap consecutive numbers in a list.", |
| "examples": [ |
| { |
| "input": [ |
| "BOS", |
| 2, |
| 4, |
| 2, |
| 6, |
| 4, |
| 8, |
| 6, |
| 1, |
| 3 |
| ], |
| "output": [ |
| "BOS", |
| 4.0, |
| 2.0, |
| 6.0, |
| 2.0, |
| 8.0, |
| 4.0, |
| 1.0, |
| 6.0, |
| 3.0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 4, |
| 1, |
| 7, |
| 5, |
| 1, |
| 4, |
| 0, |
| 9, |
| 5 |
| ], |
| "output": [ |
| "BOS", |
| 1.0, |
| 4.0, |
| 5.0, |
| 7.0, |
| 4.0, |
| 1.0, |
| 9.0, |
| 0.0, |
| 5.0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 10, |
| 10, |
| 7, |
| 4, |
| 3, |
| 7, |
| 7, |
| 2, |
| 5 |
| ], |
| "output": [ |
| "BOS", |
| 10.0, |
| 10.0, |
| 4.0, |
| 7.0, |
| 7.0, |
| 3.0, |
| 2.0, |
| 7.0, |
| 5.0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 8, |
| 0, |
| 10, |
| 10, |
| 9, |
| 2, |
| 6, |
| 3, |
| 8 |
| ], |
| "output": [ |
| "BOS", |
| 0.0, |
| 8.0, |
| 10.0, |
| 10.0, |
| 2.0, |
| 9.0, |
| 3.0, |
| 6.0, |
| 8.0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 6, |
| 3, |
| 10, |
| 7, |
| 4, |
| 6, |
| 9, |
| 2, |
| 6 |
| ], |
| "output": [ |
| "BOS", |
| 3.0, |
| 6.0, |
| 7.0, |
| 10.0, |
| 6.0, |
| 4.0, |
| 2.0, |
| 9.0, |
| 6.0 |
| ] |
| } |
| ], |
| "is_categorical": true |
| }, |
| "program": "len = rasp.SelectorWidth(rasp.Select(rasp.indices, rasp.indices, rasp.Comparison.TRUE)).named('len')\nswaper = rasp.SequenceMap(lambda idx, L: idx if (idx == L - 1 and idx % 2 == 0) else (idx + 1 if idx % 2 == 0 else idx - 1), rasp.indices, len).named('swaper')\nswap_selector = rasp.Select(rasp.indices, swaper, rasp.Comparison.EQ).named('swap_selector')\nswapped = rasp.Aggregate(swap_selector, rasp.tokens).named('swapped')\nreturn swapped", |
| "components": [ |
| { |
| "id": "L0H0_ATTN", |
| "hook": "blocks.0.attn.hook_result[0]", |
| "role": { |
| "tag": "AGGREGATOR", |
| "note": "Produces a shared sequence-level size signal used to handle the last element correctly during swapping." |
| }, |
| "rasp_vars": [ |
| "len" |
| ], |
| "labels": [ |
| "selector_width_4_selector_width_attn_output" |
| ] |
| }, |
| { |
| "id": "L0_MLP", |
| "hook": "blocks.0.mlp.hook_post", |
| "role": { |
| "tag": "MAPPER", |
| "note": "Turns the length-related signal into a sequence-length feature." |
| }, |
| "rasp_vars": [ |
| "len" |
| ], |
| "labels": [ |
| "selector_width_4_selector_width_attn_output", |
| "selector_width_4" |
| ] |
| }, |
| { |
| "id": "L1_MLP", |
| "hook": "blocks.1.mlp.hook_post", |
| "role": { |
| "tag": "COMBINER", |
| "note": "For each position, computes the index of the element it should swap with (neighbor, with end-of-sequence handling)." |
| }, |
| "rasp_vars": [ |
| "swaper" |
| ], |
| "labels": [ |
| "sequence_map_3" |
| ] |
| }, |
| { |
| "id": "L2H0_ATTN", |
| "hook": "blocks.2.attn.hook_result[0]", |
| "role": { |
| "tag": "ROUTER", |
| "note": "Moves values so each position receives the value from its swap partner." |
| }, |
| "rasp_vars": [ |
| "swapped" |
| ], |
| "labels": [ |
| "aggregate_1" |
| ] |
| } |
| ] |
| } |
|
|