Datasets:
File size: 1,765 Bytes
7f9a652 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | """Turn questions into prompts for any LLM / RAG / agent system.
usage: python make_prompts.py --qa data/dev --out prompts.jsonl [--with-context-hint]
Each output line: {"id", "prompt"}. Send `prompt` to your system, then write
{"id", "answer"} lines and score them with score.py.
"""
import argparse, glob, json, os
INSTR = ("Answer the question using only the named dataset. Reply with the answer only: "
"a number (no units), a name or code exactly as written in the data, true/false, "
"or a JSON list when a list is asked for. If the dataset does not contain the answer, reply null.")
def main():
ap = argparse.ArgumentParser()
ap.add_argument('--qa', required=True)
ap.add_argument('--out', required=True)
ap.add_argument('--with-context-hint', action='store_true', help='add the Hugging Face repo id so a tool-using agent knows where to look')
a = ap.parse_args()
files = sorted(glob.glob(os.path.join(a.qa, '*.jsonl'))) if os.path.isdir(a.qa) else [a.qa]
n = 0
with open(a.out, 'w', encoding='utf-8') as f:
for fn in files:
for line in open(fn, encoding='utf-8'):
it = json.loads(line)
p = INSTR + '\n\n'
if a.with_context_hint:
p += f"Dataset: https://huggingface.co/datasets/{it['dataset']} (revision {it['revision']})\n"
if it.get('answer_format'):
p += f"Answer format: {it['answer_format']}\n"
p += f"Question: {it['question']}"
f.write(json.dumps({'id': it['id'], 'prompt': p}, ensure_ascii=False) + '\n')
n += 1
print(n, 'prompts ->', a.out)
if __name__ == '__main__':
main()
|