| { |
| "task": { |
| "id": "case_111", |
| "name": "last_element_with_zero_padding", |
| "summary": "Returns the last element of the sequence and pads the rest with zeros.", |
| "examples": [ |
| { |
| "input": [ |
| "BOS", |
| 2, |
| 4, |
| 2, |
| 6, |
| 4, |
| 8, |
| 6, |
| 1, |
| 3 |
| ], |
| "output": [ |
| "BOS", |
| 3.0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 4, |
| 1, |
| 7, |
| 5, |
| 1, |
| 4, |
| 0, |
| 9, |
| 5 |
| ], |
| "output": [ |
| "BOS", |
| 5.0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 10, |
| 10, |
| 7, |
| 4, |
| 3, |
| 7, |
| 7, |
| 2, |
| 5 |
| ], |
| "output": [ |
| "BOS", |
| 5.0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 8, |
| 0, |
| 10, |
| 10, |
| 9, |
| 2, |
| 6, |
| 3, |
| 8 |
| ], |
| "output": [ |
| "BOS", |
| 8.0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0 |
| ] |
| }, |
| { |
| "input": [ |
| "BOS", |
| 6, |
| 3, |
| 10, |
| 7, |
| 4, |
| 6, |
| 9, |
| 2, |
| 6 |
| ], |
| "output": [ |
| "BOS", |
| 6.0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0, |
| 0 |
| ] |
| } |
| ], |
| "is_categorical": true |
| }, |
| "program": "length = rasp.SelectorWidth(rasp.Select(rasp.tokens, rasp.tokens, rasp.Comparison.TRUE)).named(\"length\")\nlast_element_selector = rasp.Select(rasp.indices, rasp.Map(lambda x: x - 1, length), rasp.Comparison.EQ).named(\"last_element_selector\")\nlast_element_sequence = rasp.Aggregate(last_element_selector, rasp.tokens).named(\"last_element_sequence\")\nreturn rasp.SequenceMap(lambda x, y: x if y == 0 else 0, last_element_sequence, rasp.indices)", |
| "components": [ |
| { |
| "id": "L0H0_ATTN", |
| "hook": "blocks.0.attn.hook_result[0]", |
| "role": { |
| "tag": "AGGREGATOR", |
| "note": "Produces a shared sequence length signal used to identify the last position." |
| }, |
| "rasp_vars": [ |
| "length" |
| ], |
| "labels": [ |
| "length_5_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": [ |
| "length" |
| ], |
| "labels": [ |
| "length_5", |
| "length_5_selector_width_attn_output" |
| ] |
| }, |
| { |
| "id": "L1_MLP", |
| "hook": "blocks.1.mlp.hook_post", |
| "role": { |
| "tag": "MAPPER", |
| "note": "Computes the last element's index by applying element-wise subtraction to the sequence-length feature." |
| }, |
| "rasp_vars": [ |
| "last_index" |
| ], |
| "labels": [ |
| "map_4" |
| ] |
| }, |
| { |
| "id": "L2H0_ATTN", |
| "hook": "blocks.2.attn.hook_result[0]", |
| "role": { |
| "tag": "ROUTER", |
| "note": "Retrieves the last token and makes it available for placement into the output sequence." |
| }, |
| "rasp_vars": [ |
| "last_element_sequence" |
| ], |
| "labels": [ |
| "last_element_sequence_2" |
| ] |
| }, |
| { |
| "id": "L2_MLP", |
| "hook": "blocks.2.mlp.hook_post", |
| "role": { |
| "tag": "COMBINER", |
| "note": "Outputs the last token in the first slot and writes zeros in every other slot." |
| }, |
| "rasp_vars": [ |
| "output_sequence" |
| ], |
| "labels": [ |
| "sequence_map_1" |
| ] |
| } |
| ] |
| } |
|
|