Download slm_instruct_bench_prepare.py from Emergent-Knowledge/assay: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/datasets/Emergent-Knowledge/assay/resolve/main/slm_instruct_bench_prepare.py
- Command line
-
hf download hf://datasets/Emergent-Knowledge/assay/slm_instruct_bench_prepare.py
-
curl -L -o slm_instruct_bench_prepare.py https://huggingface.co/datasets/Emergent-Knowledge/assay/resolve/main/slm_instruct_bench_prepare.py
2.23 kB
| """Render the next request for each item without making any inference calls. | |
| python3 prepare_requests.py --data slm_instruct_bench.jsonl > requests.jsonl | |
| python3 prepare_requests.py --data slm_instruct_bench.jsonl --responses responses.jsonl | |
| Completed single-turn items and episodes are omitted. Actual response history is | |
| retained; no gold answer, check, category, or future user turn is exposed early. | |
| """ | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from slm_instruct_bench_grade import contract,next_messages | |
| def prepare(items,submitted): | |
| known={r['id'] for r in items} | |
| if set(submitted)-known:raise ValueError('Unknown response IDs') | |
| out=[] | |
| for item in items: | |
| supplied=submitted.get(item['id']) | |
| if contract(item)['type']=='episode': | |
| history=[] if supplied is None else supplied | |
| if not isinstance(history,list) or not all(isinstance(v,str) for v in history):raise ValueError('Episode needs an array of actual string responses: '+item['id']) | |
| if len(history)>len(contract(item)['turns']):raise ValueError('Too many episode responses: '+item['id']) | |
| else: | |
| if supplied is not None and not isinstance(supplied,str):raise ValueError('Single-turn item needs a string: '+item['id']) | |
| history=[] if supplied is None else [supplied] | |
| messages=next_messages(item,history) | |
| if messages is not None:out.append({'id':item['id'],'messages':messages}) | |
| return out | |
| def main(): | |
| p=argparse.ArgumentParser(description=__doc__);p.add_argument('--data',type=Path,required=True);p.add_argument('--responses',type=Path) | |
| a=p.parse_args();items=[json.loads(s) for s in a.data.read_text().splitlines()];submitted={} | |
| if a.responses: | |
| for line in a.responses.read_text().splitlines(): | |
| r=json.loads(line);rid=r['id'] | |
| if rid in submitted:raise ValueError('Duplicate response ID '+rid) | |
| if ('response' in r)==('responses' in r):raise ValueError('Supply exactly one response or responses field') | |
| submitted[rid]=r.get('responses',r.get('response')) | |
| for request in prepare(items,submitted):print(json.dumps(request,ensure_ascii=False)) | |
| if __name__=='__main__':main() | |