"""Public long-document QA (LongBench v1 subsets). Raw jsonl obtained from the HF dataset repo THUDM/LongBench (data.zip).""" from __future__ import annotations import json, hashlib from pathlib import Path from ..util import ROOT, sha256_text RAW = ROOT / "data" / "raw" / "longbench" / "data" SUBSETS = {"qasper": "F1", "2wikimqa": "F1", "hotpotqa": "F1", "musique": "F1", "multifieldqa_en": "F1"} def load_subset(name: str) -> list[dict]: rows = [json.loads(l) for l in open(RAW / f"{name}.jsonl", encoding="utf-8")] out = [] for r in rows: out.append({"document_id": f"lb_{name}_{r['_id']}", "subset": name, "text": r["context"], "char_len": len(r["context"]), "document_hash": sha256_text(r["context"]), "questions": [{"question_id": "q00", "qtype": name, "question": r["input"], "answer": r["answers"][0], "aliases": r["answers"][1:], "answer_type": "qa_f1", "tolerance": 0.0, "supporting_fact_ids": [], "answer_position_frac": -1.0}], "facts": [], "length_words": r["length"]}) return out