{ "task": { "id": "case_3", "name": "frac_prevs", "summary": "Returns the fraction of 'x' in the input up to the i-th position for all i.", "examples": [ { "input": [ "BOS", "c", "x", "a", "c" ], "output": [ "BOS", 0.0, 0.5, 0.3333333333333333, 0.25 ] }, { "input": [ "BOS", "c", "b", "c", "c" ], "output": [ "BOS", 0.0, 0.0, 0.0, 0.0 ] }, { "input": [ "BOS", "c", "c", "x", "a" ], "output": [ "BOS", 0.0, 0.0, 0.3333333333333333, 0.25 ] }, { "input": [ "BOS", "c", "x", "a", "a" ], "output": [ "BOS", 0.0, 0.5, 0.3333333333333333, 0.25 ] }, { "input": [ "BOS", "x", "x", "x", "c" ], "output": [ "BOS", 1.0, 1.0, 1.0, 0.75 ] } ], "is_categorical": false }, "program": "is_x = (rasp.tokens == \"x\").named(\"is_x\"); bools = rasp.numerical(is_x); prevs = rasp.Select(rasp.indices, rasp.indices, rasp.Comparison.LEQ); return rasp.numerical(rasp.Aggregate(prevs, bools, default=0)).named(\"frac_prevs\")", "components": [ { "id": "L0_MLP", "hook": "blocks.0.mlp.hook_post", "role": { "tag": "INDICATOR", "note": "Computes per-position feature indicating whether the token at that position is 'x' or not." }, "rasp_vars": [ "is_x" ], "labels": [ "is_x_3" ] }, { "id": "L1H2_ATTN", "hook": "blocks.1.attn.hook_result[2]", "role": { "tag": "AGGREGATOR", "note": "Aggregates prefix fraction by attending over previous positions." }, "rasp_vars": [ "prevs", "frac_prevs" ], "labels": [ "frac_prevs_1" ] } ] }