Download alea/gen_jb3.py from Akahsizrr/alea-runs: direct link, hf CLI and curl.
- Browser
- Download file 13 kB
-
https://huggingface.co/datasets/Akahsizrr/alea-runs/resolve/73f446d1f95626796bdcbd2f22d7bfb559063136/alea/gen_jb3.py
- Command line
-
hf download hf://datasets/Akahsizrr/alea-runs@73f446d1f95626796bdcbd2f22d7bfb559063136/alea/gen_jb3.py
-
curl -L -o gen_jb3.py https://huggingface.co/datasets/Akahsizrr/alea-runs/resolve/73f446d1f95626796bdcbd2f22d7bfb559063136/alea/gen_jb3.py
13 kB
| """gen_jb3: LONG-document reasoning — multi-section policies with nested | |
| exceptions, judge-style verdicts, multi-constraint chains. | |
| Hard tier needs 1-4k token docs where the answer depends on composing | |
| several sections in order (base rule -> endorsement override -> | |
| exception-to-endorsement -> global condition). These generators build | |
| that structure deterministically so the correct answer is exact. | |
| """ | |
| import argparse | |
| import json | |
| import random | |
| rng = random.Random(31337) | |
| def choice(state, instr, crit, correct_key, family): | |
| keys = list(crit.keys()) | |
| tgt = [0.0] * len(keys) | |
| tgt[keys.index(correct_key)] = 1.0 | |
| return {"state": state, | |
| "questions": {"q0": {"type": "choice", "instructions": instr, | |
| "criteria": crit}}, | |
| "targets": {"q0": tgt}, "family": family} | |
| def noul(state, instr, val, family): | |
| return {"state": state, | |
| "questions": {"q0": {"type": "noul", "instructions": instr}}, | |
| "targets": {"q0": float(val)}, "family": family} | |
| # ---------- long insurance/loan/policy docs ---------- | |
| def gen_longpolicy(n): | |
| """Multi-section policy with exception chains -> adjudication.""" | |
| out = [] | |
| for _ in range(n): | |
| # --- document skeleton --- | |
| cov_window = rng.choice([30, 60, 90]) | |
| late_days = rng.choice([30, 45]) | |
| ded = rng.choice([250, 500]) | |
| cap = rng.choice([2000, 5000, 10000]) | |
| region_ok = rng.choice([True, False]) | |
| secs = [ | |
| "MASTER SERVICES AND PROTECTION AGREEMENT", | |
| "Document ref: MPA-%d" % rng.randint(1000, 9999), | |
| "In force: %s through %s." % ( | |
| rng.choice(["01 Jan 2024", "01 Feb 2024"]), | |
| rng.choice(["31 Dec 2025", "31 Dec 2026"])), | |
| "", | |
| "1. DEFINITIONS", | |
| " 1.1 'Covered Event' means an event listed in Section 3.", | |
| " 1.2 'Territory' means the coverage area in Schedule A.", | |
| " 1.3 'Prompt Notice' means notice within %d days." % late_days, | |
| "", | |
| "2. SCOPE", | |
| " 2.1 This agreement applies to claims arising during the " | |
| "in-force period.", | |
| " 2.2 Claims arising outside the Territory are excluded " | |
| "absent a Territory Endorsement.", | |
| "", | |
| "3. COVERED EVENTS", | |
| " 3.1 Accidental damage reported within %d days." % cov_window, | |
| " 3.2 Theft with a filed police report.", | |
| " 3.3 Mechanical failure not caused by misuse.", | |
| "", | |
| "4. EXCLUSIONS", | |
| " 4.1 Cosmetic damage is excluded.", | |
| " 4.2 Events arising from unauthorized modification are " | |
| "excluded.", | |
| " 4.3 Events occurring before the in-force date are excluded.", | |
| "", | |
| "5. CONDITIONS PRECEDENT", | |
| " 5.1 Prompt Notice is a condition precedent to coverage.", | |
| " 5.2 A deductible of $%d applies per claim." % ded, | |
| "", | |
| "6. ENDORSEMENTS", | |
| ] | |
| # endorsements create the exception chains | |
| e_theft_no_police = rng.random() < 0.4 | |
| e_territory = rng.random() < 0.5 | |
| e_mod = rng.random() < 0.35 | |
| if e_theft_no_police: | |
| secs.append(" E-T1: theft claims without a police report are " | |
| "covered up to $%d if reported with two forms of " | |
| "proof of ownership." % cap) | |
| if e_territory: | |
| secs.append(" E-TR: the Territory exclusion in 2.2 is waived " | |
| "for losses occurring within 50 km of the Territory " | |
| "boundary.") | |
| if e_mod: | |
| secs.append(" E-M1: Section 4.2 does not apply where the " | |
| "modification was performed by an authorized " | |
| "service center.") | |
| secs += ["", | |
| "7. CLAIMS PROCEDURE", | |
| " 7.1 All claims must be filed via the portal.", | |
| " 7.2 The insurer responds within 15 business days.", | |
| "", | |
| "8. GENERAL", | |
| " 8.1 This agreement is governed by the laws of the " | |
| "issuing jurisdiction.", | |
| " 8.2 Nothing herein limits statutory rights."] | |
| # --- the claim --- | |
| event = rng.choice(["accident", "theft", "mechanical"]) | |
| reported = rng.choice(["prompt", "late"]) | |
| outside = rng.random() < 0.4 | |
| police = rng.random() < 0.6 | |
| modded = rng.random() < 0.35 | |
| auth_mod = modded and (rng.random() < 0.5) | |
| facts = ["Loss date: %s 2025 (in-force period)." % | |
| rng.choice(["Apr 3", "Jul 19", "Oct 8"]), | |
| "Event type: %s." % event] | |
| if event == "accident": | |
| facts.append("Damage is structural, not cosmetic.") | |
| facts.append("Reported %d days after the event." % | |
| (rng.randint(1, cov_window - 3) if reported == "prompt" | |
| else cov_window + rng.randint(3, 20))) | |
| if event == "theft": | |
| facts.append("Police report %s." % | |
| ("filed same day" if police else "was NOT filed")) | |
| if e_theft_no_police and not police: | |
| facts.append("Claimant supplied %s." % | |
| rng.choice(["two proofs of ownership", | |
| "one proof of ownership"])) | |
| if event == "mechanical": | |
| facts.append("Unit %s." % | |
| ("was modified by an authorized service center" | |
| if auth_mod else | |
| "has an unauthorized third-party modification" | |
| if modded else "is unmodified")) | |
| facts.append("Reported %d days after the event." % | |
| rng.randint(1, cov_window)) | |
| if outside: | |
| facts.append("Loss occurred %d km outside the Territory " | |
| "boundary." % rng.choice([20, 80])) | |
| if reported == "late" and event != "accident": | |
| facts.append("Claim filed %d days after the loss." % | |
| (late_days + rng.randint(1, 15))) | |
| elif event != "accident": | |
| facts.append("Claim filed %d days after the loss." % | |
| rng.randint(1, late_days - 2)) | |
| # --- adjudicate --- | |
| if event == "accident" and reported == "late": | |
| correct = "deny_late" | |
| elif event == "accident": | |
| correct = "pay" | |
| elif event == "theft": | |
| if police: | |
| correct = "pay" | |
| elif e_theft_no_police: | |
| two_proofs = any("two proofs" in f for f in facts) | |
| correct = "pay_capped" if two_proofs else "deny_condition" | |
| else: | |
| correct = "deny_condition" | |
| else: # mechanical | |
| if modded and auth_mod and e_mod: | |
| correct = "pay" | |
| elif modded and auth_mod and not e_mod: | |
| correct = "deny_excluded" | |
| elif modded and not auth_mod: | |
| correct = "deny_excluded" | |
| else: | |
| correct = "pay" | |
| if correct == "pay" and outside: | |
| near = "20 km" in " ".join(facts) | |
| correct = "pay" if (e_territory and near) else "deny_excluded" | |
| elif outside and correct.startswith("pay"): | |
| near = "20 km" in " ".join(facts) | |
| correct = "pay" if (e_territory and near) else "deny_excluded" | |
| if reported == "late" and event != "accident" and correct == "pay": | |
| correct = "deny_late" | |
| crit = { | |
| "pay": "Pay the claim less the deductible", | |
| "pay_capped": "Pay subject to the endorsement cap", | |
| "deny_late": "Deny: notice condition not met", | |
| "deny_excluded": "Deny: exclusion applies", | |
| "deny_condition": "Deny: a coverage condition was not met", | |
| } | |
| st = "\n".join(secs) + "\n\nCLAIM:\n" + "\n".join(facts) | |
| out.append(choice(st, "Adjudicate the claim. Apply sections in " | |
| "order; endorsements modify earlier sections; " | |
| "conditions precedent bind first.", crit, | |
| correct, "jb3_longpolicy")) | |
| return out | |
| # ---------- judge: verify a verdict ---------- | |
| def gen_judge(n): | |
| """Doc + candidate verdict -> agree/disagree (judge_hard style).""" | |
| out = [] | |
| for _ in range(n): | |
| a = rng.randint(100, 900) | |
| b = rng.randint(100, 900) | |
| c = rng.randint(100, 900) | |
| col = rng.choice(["revenue", "cost", "units"]) | |
| rec = {"revenue": a, "cost": b, "units": c} | |
| rec["margin"] = round((a - b) / a, 3) | |
| st = ("Record:\n revenue: %d\n cost: %d\n units: %d\n margin: " | |
| "%.3f\n region: %s\n quarter: Q%d" % | |
| (a, b, c, rec["margin"], rng.choice(["EU", "NA", "APAC"]), | |
| rng.randint(1, 4))) | |
| # candidate verdict — correct half the time | |
| kind = rng.choice(["margin", "sum", "max"]) | |
| if kind == "margin": | |
| true_v = rec["margin"] | |
| wrong_v = round((a - b) / b, 3) | |
| claim = "the margin is %.3f" % (true_v if rng.random() < 0.5 | |
| else wrong_v) | |
| ok = ("%.3f" % true_v) in claim | |
| elif kind == "sum": | |
| true_v = a + b | |
| wrong_v = a + b + rng.choice([-1, 1]) * rng.randint(5, 50) | |
| claim = "revenue plus cost equals %d" % (true_v | |
| if rng.random() < 0.5 else wrong_v) | |
| ok = str(true_v) in claim | |
| else: | |
| big = max(rec.values()) | |
| wrong = min(rec.values()) | |
| claim = "the largest field is %d" % (big if rng.random() < 0.5 | |
| else wrong) | |
| ok = str(big) in claim | |
| st += "\n\nAnalyst verdict: \"%s\"." % claim | |
| out.append(choice(st, "Judge the verdict: does it follow from the " | |
| "record?", | |
| {"correct": "Verdict is correct", | |
| "incorrect": "Verdict is incorrect"}, | |
| "correct" if ok else "incorrect", "jb3_judge")) | |
| return out | |
| # ---------- multi-hop temporal chains ---------- | |
| def gen_temporal_chain(n): | |
| """3-4 step date/shift chains — multi_hop style.""" | |
| import datetime as dt | |
| out = [] | |
| for _ in range(n): | |
| y = rng.choice([2024, 2025]) | |
| m, d = rng.randint(1, 12), rng.randint(1, 28) | |
| try: | |
| base = dt.date(y, m, d) | |
| except ValueError: | |
| continue | |
| hops = [rng.randint(3, 14) for _ in range(3)] | |
| wds = [h * rng.choice([1, 1]) for h in hops] | |
| steps_txt = [] | |
| cur = base | |
| for i, h in enumerate(hops): | |
| steps_txt.append("Step %d: add %d days." % (i + 1, h)) | |
| cur += dt.timedelta(days=h) | |
| # ask for final weekday or date | |
| ask = rng.choice(["weekday", "date"]) | |
| st = ("Start date: %s.\n%s\n" % (base.strftime("%A, %B %d, %Y"), | |
| "\n".join(steps_txt))) | |
| if ask == "weekday": | |
| opts = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", | |
| "Saturday", "Sunday"] | |
| rng.shuffle(opts) | |
| crit = {o: "final day is %s" % o for o in opts} | |
| out.append(choice(st, "Apply each step in order and choose the " | |
| "final weekday.", crit, | |
| cur.strftime("%A"), "jb3_temporal_chain")) | |
| else: | |
| opts = [cur.strftime("%B %d")] | |
| for _ in range(3): | |
| w = cur + dt.timedelta(days=rng.choice([-3, -2, -1, 1, 2, 3])) | |
| opts.append(w.strftime("%B %d")) | |
| order = list(range(4)); rng.shuffle(order) | |
| shuffled = [opts[j] for j in order] | |
| crit = {"d%d" % i: shuffled[i] for i in range(4)} | |
| out.append(choice(st, "Apply each step in order and choose the " | |
| "final date.", crit, | |
| "d%d" % order.index(0), "jb3_temporal_chain")) | |
| return out | |
| GENS = {"longpolicy": gen_longpolicy, "judge": gen_judge, | |
| "temporal_chain": gen_temporal_chain} | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--out", default="data/jb3.jsonl") | |
| ap.add_argument("--per", type=int, default=8000) | |
| args = ap.parse_args() | |
| rows = [] | |
| for name, fn in GENS.items(): | |
| got = fn(args.per) | |
| print(name, len(got)) | |
| rows += got | |
| rng.shuffle(rows) | |
| with open(args.out, "w") as f: | |
| for r in rows: | |
| f.write(json.dumps(r, ensure_ascii=False) + "\n") | |
| print("TOTAL", len(rows), "->", args.out) | |
| if __name__ == "__main__": | |
| main() | |