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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""gen_jb: synthetic generators for JevBench-STYLE hard families.
|
| 2 |
+
|
| 3 |
+
Pure synthetic, programmatically exact answers. Original content only —
|
| 4 |
+
no benchmark items are read, copied or paraphrased. Families target the
|
| 5 |
+
measured weak spots: intent collapse, multi-hop, temporal, routing,
|
| 6 |
+
policy adjudication, traps/decoys, ambiguity, severity ordinals,
|
| 7 |
+
probability, extraction-verify, dedup/consistency.
|
| 8 |
+
|
| 9 |
+
Emit rows in alea format:
|
| 10 |
+
{"state": str, "questions": {"q0": {...}}, "targets": {"q0": ...},
|
| 11 |
+
"family": str}
|
| 12 |
+
"""
|
| 13 |
+
import argparse
|
| 14 |
+
import json
|
| 15 |
+
import random
|
| 16 |
+
|
| 17 |
+
rng = random.Random(4242)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def choice(state, instr, crit, correct_key, family):
|
| 21 |
+
keys = list(crit.keys())
|
| 22 |
+
tgt = [0.0] * len(keys)
|
| 23 |
+
tgt[keys.index(correct_key)] = 1.0
|
| 24 |
+
return {"state": state,
|
| 25 |
+
"questions": {"q0": {"type": "choice", "instructions": instr,
|
| 26 |
+
"criteria": crit}},
|
| 27 |
+
"targets": {"q0": tgt}, "family": family}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def noul(state, instr, val, family):
|
| 31 |
+
return {"state": state,
|
| 32 |
+
"questions": {"q0": {"type": "noul", "instructions": instr}},
|
| 33 |
+
"targets": {"q0": float(val)}, "family": family}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# ---------------- intent (anti-mode-collapse) ----------------
|
| 37 |
+
|
| 38 |
+
INTENT_BANK = {
|
| 39 |
+
"cancel_order": ["cancel my order", "I want to cancel the order I just "
|
| 40 |
+
"placed", "please cancel order", "undo my purchase",
|
| 41 |
+
"I changed my mind, cancel it"],
|
| 42 |
+
"track_order": ["where is my package", "track my shipment", "when will my "
|
| 43 |
+
"order arrive", "status of my delivery", "is my order "
|
| 44 |
+
"shipped yet"],
|
| 45 |
+
"refund": ["I want my money back", "issue a refund", "refund me for the "
|
| 46 |
+
"broken item", "return my payment", "give me a refund"],
|
| 47 |
+
"change_address": ["update my shipping address", "I moved, change the "
|
| 48 |
+
"delivery address", "send it to my new address",
|
| 49 |
+
"correct my address", "reroute to a different address"],
|
| 50 |
+
"report_damage": ["the item arrived broken", "my package was damaged",
|
| 51 |
+
"the product is defective", "it came cracked",
|
| 52 |
+
"screen is shattered on arrival"],
|
| 53 |
+
"billing_question": ["why was I charged twice", "question about my "
|
| 54 |
+
"invoice", "explain this charge on my card",
|
| 55 |
+
"what is this billing line", "you billed me wrong"],
|
| 56 |
+
"upgrade_plan": ["upgrade my subscription", "I want the premium tier",
|
| 57 |
+
"move me to the pro plan", "upgrade my account",
|
| 58 |
+
"switch to the business plan"],
|
| 59 |
+
"reset_password": ["forgot my password", "reset my login", "I cant sign "
|
| 60 |
+
"in, need a password reset", "help me get back into "
|
| 61 |
+
"my account", "password not working"],
|
| 62 |
+
"cancel_subscription": ["cancel my subscription", "stop the monthly "
|
| 63 |
+
"charges", "end my membership", "I want to "
|
| 64 |
+
"unsubscribe", "cancel my plan"],
|
| 65 |
+
"technical_issue": ["the app keeps crashing", "website wont load",
|
| 66 |
+
"getting an error message", "feature is broken",
|
| 67 |
+
"nothing happens when I click"],
|
| 68 |
+
"complaint": ["I am very unhappy with your service", "this is "
|
| 69 |
+
"unacceptable", "I want to file a complaint", "worst "
|
| 70 |
+
"experience ever", "terrible support"],
|
| 71 |
+
"praise": ["great job on the delivery", "love the new update", "thanks "
|
| 72 |
+
"for the quick help", "excellent service", "very happy with "
|
| 73 |
+
"the product"],
|
| 74 |
+
"set_alarm": ["wake me at 7", "set an alarm for tomorrow morning",
|
| 75 |
+
"alarm at 6:30 please", "remind me at 8am", "set a timer "
|
| 76 |
+
"for 20 minutes"],
|
| 77 |
+
"play_music": ["play some jazz", "put on my workout playlist", "play "
|
| 78 |
+
"the new album", "start the radio", "play music"],
|
| 79 |
+
"weather": ["what is the weather today", "is it going to rain",
|
| 80 |
+
"forecast for the weekend", "temperature outside",
|
| 81 |
+
"will it snow tonight"],
|
| 82 |
+
"send_message": ["text mom I am running late", "send a message to "
|
| 83 |
+
"John", "tell Sarah the meeting moved", "message the "
|
| 84 |
+
"group chat", "send an sms to my boss"],
|
| 85 |
+
"book_flight": ["book a flight to Denver", "I need a ticket to "
|
| 86 |
+
"Chicago next Friday", "find me flights to Miami",
|
| 87 |
+
"reserve a seat on the morning flight", "book airfare"],
|
| 88 |
+
"restaurant_reservation": ["book a table for two tonight", "reserve a "
|
| 89 |
+
"spot at the italian place", "dinner "
|
| 90 |
+
"reservation for four", "table for 7pm",
|
| 91 |
+
"book a restaurant"],
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
INTENT_TEMPLATES = ["{}", "Hey, {}", "Hi - {}", "{}", "Can you {}",
|
| 95 |
+
"Please {}", "I need help: {}", "{}", "{}", "{}"]
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def gen_intent(n):
|
| 99 |
+
names = list(INTENT_BANK)
|
| 100 |
+
out = []
|
| 101 |
+
for _ in range(n):
|
| 102 |
+
true = rng.choice(names)
|
| 103 |
+
phrase = rng.choice(INTENT_BANK[true])
|
| 104 |
+
tmpl = rng.choice(INTENT_TEMPLATES)
|
| 105 |
+
msg = tmpl.format(phrase)
|
| 106 |
+
# distractors: intents sharing vocabulary where possible
|
| 107 |
+
vocab = {"order": ["cancel_order", "track_order"],
|
| 108 |
+
"address": ["change_address"], "cancel": ["cancel_order",
|
| 109 |
+
"cancel_subscription"], "book": ["book_flight",
|
| 110 |
+
"restaurant_reservation"], "refund": ["refund",
|
| 111 |
+
"billing_question"], "set": ["set_alarm"]}
|
| 112 |
+
pool = [x for x in names if x != true]
|
| 113 |
+
for w, cands in vocab.items():
|
| 114 |
+
if w in phrase.lower():
|
| 115 |
+
pool = cands[:1] + [x for x in pool if x not in cands]
|
| 116 |
+
k = rng.randint(3, 6)
|
| 117 |
+
opts = [true] + rng.sample(pool, k)
|
| 118 |
+
rng.shuffle(opts)
|
| 119 |
+
crit = {o: f"Route to the '{o.replace('_', ' ')}' handler" for o in opts}
|
| 120 |
+
st = ("Incoming user message to the assistant router:\n\n\"%s\"" % msg)
|
| 121 |
+
out.append(choice(st, "Pick the single intent this message maps to.",
|
| 122 |
+
crit, true, "jb_intent"))
|
| 123 |
+
return out
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# ---------------- multi-hop arithmetic ----------------
|
| 127 |
+
|
| 128 |
+
def gen_multihop(n):
|
| 129 |
+
out = []
|
| 130 |
+
for _ in range(n):
|
| 131 |
+
kind = rng.choice(["rates", "diff", "combine", "percent"])
|
| 132 |
+
if kind == "rates":
|
| 133 |
+
a = rng.randint(3, 9); b = rng.randint(2, 8); c = rng.randint(2, 6)
|
| 134 |
+
st = (f"A warehouse packs {a} crates per hour. It operates {b} "
|
| 135 |
+
f"hours per shift and runs {c} shifts this week. A client "
|
| 136 |
+
f"ordered {{}} crates.\n\nHow many crates does the "
|
| 137 |
+
f"warehouse pack this week?")
|
| 138 |
+
ans = a * b * c
|
| 139 |
+
st = st.replace("{}", str(rng.randint(50, 400)))
|
| 140 |
+
ds = [ans + rng.choice([-1, 1]) * rng.randint(2, 20)
|
| 141 |
+
for _ in range(3)]
|
| 142 |
+
elif kind == "diff":
|
| 143 |
+
x = rng.randint(200, 900); y = rng.randint(30, 199)
|
| 144 |
+
z = rng.randint(20, 90)
|
| 145 |
+
st = (f"An account starts at ${x}. A fee of ${y} is charged, "
|
| 146 |
+
f"then a deposit of ${z} arrives. A second fee of ${y//2} "
|
| 147 |
+
f"is charged.\n\nWhat is the final balance?")
|
| 148 |
+
ans = x - y + z - y // 2
|
| 149 |
+
ds = [ans + rng.choice([-1, 1]) * rng.randint(2, 30)
|
| 150 |
+
for _ in range(3)]
|
| 151 |
+
elif kind == "combine":
|
| 152 |
+
p = rng.randint(2, 6); q_ = rng.randint(3, 8); r_ = rng.randint(2, 7)
|
| 153 |
+
st = (f"Team A finishes {p} tasks per day for {q_} days. Team B "
|
| 154 |
+
f"finishes {r_} tasks per day for {q_} days.\n\nHow many "
|
| 155 |
+
f"tasks did both teams finish in total?")
|
| 156 |
+
ans = (p + r_) * q_
|
| 157 |
+
ds = [p * q_ + r_, p * q_, r_ * q_]
|
| 158 |
+
else:
|
| 159 |
+
base = rng.randint(200, 2000); pct = rng.choice([5, 10, 15, 20, 25])
|
| 160 |
+
st = (f"A subscription costs ${base} per year. It increases by "
|
| 161 |
+
f"{pct}% this year, then a ${rng.randint(10, 50)} loyalty "
|
| 162 |
+
f"credit is applied.\n\nWhat is the effective yearly cost?")
|
| 163 |
+
credit = int(st.split("$")[-1].split(" loyalty")[0])
|
| 164 |
+
ans = base * (1 + pct / 100) - credit
|
| 165 |
+
ans = round(ans, 2)
|
| 166 |
+
ds = [round(base * (1 + pct / 100), 2),
|
| 167 |
+
round(base * (1 - pct / 100), 2),
|
| 168 |
+
round(ans + rng.choice([-1, 1]) * rng.randint(5, 40), 2)]
|
| 169 |
+
opts = [f"{ans:g}"] + [f"{d:g}" for d in ds]
|
| 170 |
+
keys = [f"answer_{i}" for i in range(4)]
|
| 171 |
+
order = list(range(4)); rng.shuffle(order)
|
| 172 |
+
crit = {keys[j]: opts[j] for j in order}
|
| 173 |
+
correct = keys[order.index(0)]
|
| 174 |
+
out.append(choice(st, "Compute the answer. Only the exact value is "
|
| 175 |
+
"correct.", crit, correct, "jb_multihop"))
|
| 176 |
+
return out
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
# ---------------- temporal ----------------
|
| 180 |
+
|
| 181 |
+
WD = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
|
| 182 |
+
"Sunday"]
|
| 183 |
+
|
| 184 |
+
def gen_temporal(n):
|
| 185 |
+
out = []
|
| 186 |
+
for _ in range(n):
|
| 187 |
+
kind = rng.choice(["weekday", "deadline", "duration", "age"])
|
| 188 |
+
if kind == "weekday":
|
| 189 |
+
d0 = rng.randint(1, 28); m0 = rng.randint(1, 12)
|
| 190 |
+
off = rng.randint(3, 20)
|
| 191 |
+
import datetime as dt
|
| 192 |
+
base = dt.date(2026, m0, d0)
|
| 193 |
+
tgt_d = base + dt.timedelta(days=off)
|
| 194 |
+
st = (f"A ticket was opened on {base.strftime('%A, %B %d, %Y')}. "
|
| 195 |
+
f"The SLA requires a response within {off} calendar days.\n\n"
|
| 196 |
+
f"On which weekday does the SLA expire?")
|
| 197 |
+
opts = WD[:]
|
| 198 |
+
rng.shuffle(opts)
|
| 199 |
+
crit = {o: f"SLA expires on a {o}" for o in opts}
|
| 200 |
+
out.append(choice(st, "Choose the weekday on which the SLA "
|
| 201 |
+
"expires.", crit, tgt_d.strftime("%A"),
|
| 202 |
+
"jb_temporal"))
|
| 203 |
+
elif kind == "deadline":
|
| 204 |
+
import datetime as dt
|
| 205 |
+
m0, d0 = rng.randint(1, 12), rng.randint(1, 28)
|
| 206 |
+
try:
|
| 207 |
+
base = dt.date(2026, m0, d0)
|
| 208 |
+
except ValueError:
|
| 209 |
+
continue
|
| 210 |
+
biz = rng.randint(3, 10)
|
| 211 |
+
dd = base; added = 0
|
| 212 |
+
while added < biz:
|
| 213 |
+
dd += dt.timedelta(days=1)
|
| 214 |
+
if dd.weekday() < 5:
|
| 215 |
+
added += 1
|
| 216 |
+
st = (f"Contract signed {base.strftime('%B %d, %Y')}. Payment is "
|
| 217 |
+
f"due within {biz} business days (Mon-Fri only, ignoring "
|
| 218 |
+
f"holidays).\n\nWhat is the payment due date?")
|
| 219 |
+
wrongs = [base + dt.timedelta(days=biz),
|
| 220 |
+
dd + dt.timedelta(days=rng.choice([-2, 2])),
|
| 221 |
+
base + dt.timedelta(days=biz + 2)]
|
| 222 |
+
opts = [dd.strftime("%B %d")] + [w.strftime("%B %d")
|
| 223 |
+
for w in wrongs]
|
| 224 |
+
keys = [f"date_{i}" for i in range(4)]
|
| 225 |
+
order = list(range(4)); rng.shuffle(order)
|
| 226 |
+
crit = {keys[j]: opts[j] for j in order}
|
| 227 |
+
out.append(choice(st, "Choose the correct due date.", crit,
|
| 228 |
+
keys[order.index(0)], "jb_temporal"))
|
| 229 |
+
elif kind == "duration":
|
| 230 |
+
h1 = rng.randint(6, 22); m1 = rng.choice([0, 15, 30, 45])
|
| 231 |
+
h2 = rng.randint(6, 22); m2 = rng.choice([0, 15, 30, 45])
|
| 232 |
+
t1 = h1 * 60 + m1; t2 = h2 * 60 + m2
|
| 233 |
+
if t2 <= t1:
|
| 234 |
+
continue
|
| 235 |
+
diff = t2 - t1
|
| 236 |
+
st = (f"A shift runs from {h1:02d}:{m1:02d} to {h2:02d}:{m2:02d} "
|
| 237 |
+
f"with a {rng.choice([15, 30, 45])}-minute unpaid break.")
|
| 238 |
+
brk = int(st.split("a ")[1].split("-minute")[0])
|
| 239 |
+
ans = diff - brk
|
| 240 |
+
ds = [diff, diff - brk + rng.choice([15, 30]), diff - 60]
|
| 241 |
+
opts = [f"{ans//60}h{ans%60:02d}"] + [f"{d//60}h{d%60:02d}"
|
| 242 |
+
for d in ds]
|
| 243 |
+
keys = [f"dur_{i}" for i in range(4)]
|
| 244 |
+
order = list(range(4)); rng.shuffle(order)
|
| 245 |
+
crit = {keys[j]: opts[j] for j in order}
|
| 246 |
+
out.append(choice(st, "Choose the paid duration.", crit,
|
| 247 |
+
keys[order.index(0)], "jb_temporal"))
|
| 248 |
+
else:
|
| 249 |
+
by = rng.randint(1958, 1990); ref = rng.choice([2024, 2025, 2026])
|
| 250 |
+
st = (f"A document says the person was born in {by}. The record "
|
| 251 |
+
f"was checked in {ref}.\n\nHow old was the person when "
|
| 252 |
+
f"checked? (Assume birthday already occurred.)")
|
| 253 |
+
ans = ref - by
|
| 254 |
+
ds = [ans - 1, ans + 1, ans + rng.choice([-2, 2])]
|
| 255 |
+
opts = [str(ans)] + [str(d) for d in ds]
|
| 256 |
+
keys = [f"age_{i}" for i in range(4)]
|
| 257 |
+
order = list(range(4)); rng.shuffle(order)
|
| 258 |
+
crit = {keys[j]: opts[j] for j in order}
|
| 259 |
+
out.append(choice(st, "Choose the correct age.", crit,
|
| 260 |
+
keys[order.index(0)], "jb_temporal"))
|
| 261 |
+
return out
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
# ---------------- policy adjudication ----------------
|
| 265 |
+
|
| 266 |
+
POLICY_KINDS = [
|
| 267 |
+
{"domain": "refund",
|
| 268 |
+
"clauses": [
|
| 269 |
+
("standard", "Standard items may be returned within {D1} days for a "
|
| 270 |
+
"full refund."),
|
| 271 |
+
("final_sale", "Items marked 'final sale' cannot be returned or "
|
| 272 |
+
"refunded."),
|
| 273 |
+
("opened_media", "Opened software and media may be returned within "
|
| 274 |
+
"{D2} days only if defective."),
|
| 275 |
+
("restocking", "Electronics returns incur a {P}% restocking fee."),
|
| 276 |
+
("gift", "Gift purchases are refunded as store credit only."),
|
| 277 |
+
],
|
| 278 |
+
"facts": ["the item was marked final sale", "the item arrived defective",
|
| 279 |
+
"the return is within the allowed window", "the return is "
|
| 280 |
+
"past the allowed window", "the item was opened software",
|
| 281 |
+
"the item is electronics", "the purchase was a gift"],
|
| 282 |
+
"outcomes": ["full_refund", "store_credit", "defective_exchange",
|
| 283 |
+
"deny_return", "refund_minus_restocking"]},
|
| 284 |
+
{"domain": "insurance",
|
| 285 |
+
"clauses": [
|
| 286 |
+
("excl_flood", "Flood damage is excluded under this policy."),
|
| 287 |
+
("excl_wind", "Wind damage is excluded in coastal zones."),
|
| 288 |
+
("cover_theft", "Theft is covered up to ${L} per occurrence."),
|
| 289 |
+
("deductible", "All claims carry a ${DD} deductible."),
|
| 290 |
+
("grace", "Claims reported within {D} days of loss qualify for "
|
| 291 |
+
"expedited handling."),
|
| 292 |
+
],
|
| 293 |
+
"facts": ["the damage was caused by flooding", "the damage was caused "
|
| 294 |
+
"by wind in a coastal zone", "the loss is a theft",
|
| 295 |
+
"the claim was reported late", "the claim was reported "
|
| 296 |
+
"promptly"],
|
| 297 |
+
"outcomes": ["cover_minus_deductible", "deny_excluded_peril",
|
| 298 |
+
"deny_late_report", "cover_expedited"]},
|
| 299 |
+
{"domain": "leave",
|
| 300 |
+
"clauses": [
|
| 301 |
+
("tenure", "Employees with <{Y} year tenure get no extended leave."),
|
| 302 |
+
("parental", "Parental leave: {W} weeks paid for primary "
|
| 303 |
+
"caregivers."),
|
| 304 |
+
("medical", "Medical leave requires a physician note."),
|
| 305 |
+
("cap", "Total paid leave cannot exceed {C} weeks per year."),
|
| 306 |
+
],
|
| 307 |
+
"facts": ["the employee has 8 months tenure", "the employee has 3 years "
|
| 308 |
+
"tenure", "the request is for parental leave as primary "
|
| 309 |
+
"caregiver", "no physician note was provided", "a physician "
|
| 310 |
+
"note was provided", "the request would exceed the annual cap"],
|
| 311 |
+
"outcomes": ["approve_paid", "approve_unpaid", "deny_no_documentation",
|
| 312 |
+
"deny_tenure", "deny_cap_exceeded"]},
|
| 313 |
+
]
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def gen_policy(n):
|
| 317 |
+
out = []
|
| 318 |
+
for _ in range(n):
|
| 319 |
+
pk = rng.choice(POLICY_KINDS)
|
| 320 |
+
# instantiate numbers
|
| 321 |
+
subs = {"D1": rng.choice([14, 30, 60]), "D2": rng.choice([7, 14]),
|
| 322 |
+
"P": rng.choice([10, 15, 20]), "L": rng.choice([2000, 5000,
|
| 323 |
+
10000]), "DD": rng.choice([250, 500, 1000]),
|
| 324 |
+
"D": rng.choice([14, 30]), "Y": 1, "W": rng.choice([8, 12]),
|
| 325 |
+
"C": rng.choice([6, 8])}
|
| 326 |
+
clauses = [(cid, txt.format(**subs)) for cid, txt in pk["clauses"]]
|
| 327 |
+
fact = rng.choice(pk["facts"])
|
| 328 |
+
# pick the clause that governs + the outcome it implies
|
| 329 |
+
dom = pk["domain"]
|
| 330 |
+
if dom == "refund":
|
| 331 |
+
if "final sale" in fact:
|
| 332 |
+
res = "deny_return"; src = "final_sale"
|
| 333 |
+
elif "defective" in fact and "opened software" in fact:
|
| 334 |
+
res = "defective_exchange"; src = "opened_media"
|
| 335 |
+
elif "defective" in fact:
|
| 336 |
+
res = "defective_exchange"; src = "opened_media"
|
| 337 |
+
elif "past the allowed window" in fact:
|
| 338 |
+
res = "deny_return"; src = "standard"
|
| 339 |
+
elif "gift" in fact:
|
| 340 |
+
res = "store_credit"; src = "gift"
|
| 341 |
+
elif "electronics" in fact:
|
| 342 |
+
res = "refund_minus_restocking"; src = "restocking"
|
| 343 |
+
else:
|
| 344 |
+
res = "full_refund"; src = "standard"
|
| 345 |
+
elif dom == "insurance":
|
| 346 |
+
if "flood" in fact:
|
| 347 |
+
res = "deny_excluded_peril"; src = "excl_flood"
|
| 348 |
+
elif "wind" in fact:
|
| 349 |
+
res = "deny_excluded_peril"; src = "excl_wind"
|
| 350 |
+
elif "late" in fact:
|
| 351 |
+
res = "deny_late_report"; src = "grace"
|
| 352 |
+
elif "promptly" in fact:
|
| 353 |
+
res = "cover_expedited"; src = "grace"
|
| 354 |
+
else:
|
| 355 |
+
res = "cover_minus_deductible"; src = "cover_theft"
|
| 356 |
+
else:
|
| 357 |
+
if "8 months" in fact:
|
| 358 |
+
res = "deny_tenure"; src = "tenure"
|
| 359 |
+
elif "no physician" in fact and "medical" in " ".join(
|
| 360 |
+
c[0] for c in clauses):
|
| 361 |
+
res = "deny_no_documentation"; src = "medical"
|
| 362 |
+
elif "exceed" in fact:
|
| 363 |
+
res = "deny_cap_exceeded"; src = "cap"
|
| 364 |
+
elif "parental" in fact:
|
| 365 |
+
res = "approve_paid"; src = "parental"
|
| 366 |
+
else:
|
| 367 |
+
res = "approve_unpaid"; src = "medical"
|
| 368 |
+
policy_txt = "\n".join(f" ({i+1}) {t}" for i, (_, t)
|
| 369 |
+
in enumerate(clauses))
|
| 370 |
+
st = (f"POLICY ({dom.upper()})\n{policy_txt}\n\nCLAIM FACTS\n"
|
| 371 |
+
f"Reviewer's note: {fact}. All other facts are standard and "
|
| 372 |
+
f"unremarkable.\n\nA junior adjuster wrote: \"surface answer "
|
| 373 |
+
f"looks like a routine approval\".")
|
| 374 |
+
crit = {o: f"Outcome '{o.replace('_', ' ')}' applies" for o in
|
| 375 |
+
pk["outcomes"]}
|
| 376 |
+
out.append(choice(st, "As the adjudicator, apply the policy clauses "
|
| 377 |
+
"to the facts. The correct outcome follows the "
|
| 378 |
+
"controlling clause, not the surface impression.",
|
| 379 |
+
crit, res, "jb_policy"))
|
| 380 |
+
return out
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
# ---------------- trap / decoy ----------------
|
| 384 |
+
|
| 385 |
+
def gen_trap(n):
|
| 386 |
+
out = []
|
| 387 |
+
for _ in range(n):
|
| 388 |
+
kind = rng.choice(["stale_note", "unit_mix", "negation", "wrong_field"])
|
| 389 |
+
if kind == "stale_note":
|
| 390 |
+
mo = rng.choice(["Mar", "Apr", "May"])
|
| 391 |
+
st = (f"DATABASE RECORD (verified {mo} 2026):\n "
|
| 392 |
+
f"subscription_status: active\n "
|
| 393 |
+
f"renewal_date: {rng.randint(1,28)} Jun 2026\n\n"
|
| 394 |
+
f"UNVERIFIED STICKY NOTE (dated 2024):\n \"customer "
|
| 395 |
+
f"cancelled - account closed\"\n\n"
|
| 396 |
+
f"Is the subscription active per the verified record?")
|
| 397 |
+
out.append(choice(st, "Answer using only the verified record; "
|
| 398 |
+
"the sticky note is stale.",
|
| 399 |
+
{"active": "Subscription is active",
|
| 400 |
+
"cancelled": "Subscription is cancelled",
|
| 401 |
+
"unknown": "Cannot be determined"},
|
| 402 |
+
"active", "jb_trap"))
|
| 403 |
+
elif kind == "unit_mix":
|
| 404 |
+
a = rng.randint(2, 9); b = rng.randint(3, 12)
|
| 405 |
+
st = (f"A recipe needs {a} grams of salt per serving and serves "
|
| 406 |
+
f"{b} people. A shopper bought a {a*b} gram box and a "
|
| 407 |
+
f"{a*b*10} gram refill pack.\n\nDoes one box suffice for "
|
| 408 |
+
f"one batch of the recipe?")
|
| 409 |
+
out.append(choice(st, "Compute servings x grams; compare to the "
|
| 410 |
+
"box size, not the refill pack.",
|
| 411 |
+
{"yes_exactly": "Yes, exactly enough",
|
| 412 |
+
"yes_spare": "Yes, with spare",
|
| 413 |
+
"no": "No, insufficient"},
|
| 414 |
+
"yes_exactly", "jb_trap"))
|
| 415 |
+
elif kind == "negation":
|
| 416 |
+
st = (f"Release checklist for build {rng.randint(200,999)}:\n"
|
| 417 |
+
f" [x] unit tests pass\n [x] docs updated\n"
|
| 418 |
+
f" [ ] security scan clean\n [x] changelog written\n\n"
|
| 419 |
+
f"Policy: release is blocked only if a REQUIRED item is "
|
| 420 |
+
f"unchecked. All four items are required.")
|
| 421 |
+
out.append(choice(st, "Apply the policy literally: any unchecked "
|
| 422 |
+
"required item blocks the release.",
|
| 423 |
+
{"release_ok": "Release may proceed",
|
| 424 |
+
"blocked_security": "Blocked: security scan "
|
| 425 |
+
"not complete",
|
| 426 |
+
"blocked_docs": "Blocked: docs missing"},
|
| 427 |
+
"blocked_security", "jb_trap"))
|
| 428 |
+
else:
|
| 429 |
+
a, b = rng.randint(100, 999), rng.randint(100, 999)
|
| 430 |
+
st = (f"Spreadsheet row: quantity={a}, unit_price={b}, "
|
| 431 |
+
f"discount_pct=0, region=EU, sku_total={a + b} (this "
|
| 432 |
+
f"column holds quantity + unit_price, NOT revenue).\n\n"
|
| 433 |
+
f"Which value equals revenue (quantity x unit_price)?")
|
| 434 |
+
rev = a * b
|
| 435 |
+
ds = [a + b, rev // 10, rev + rng.choice([-1, 1]) * a]
|
| 436 |
+
opts = [f"{rev}"] + [f"{d}" for d in ds]
|
| 437 |
+
keys = [f"v{i}" for i in range(4)]
|
| 438 |
+
order = list(range(4)); rng.shuffle(order)
|
| 439 |
+
crit = {keys[j]: opts[j] for j in order}
|
| 440 |
+
out.append(choice(st, "Pick the cell semantics correctly; "
|
| 441 |
+
"sku_total is a decoy.", crit,
|
| 442 |
+
keys[order.index(0)], "jb_trap"))
|
| 443 |
+
return out
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
# ---------------- ambiguity ----------------
|
| 447 |
+
|
| 448 |
+
def gen_ambiguity(n):
|
| 449 |
+
out = []
|
| 450 |
+
for _ in range(n):
|
| 451 |
+
has = rng.random() < 0.5
|
| 452 |
+
field = rng.choice(["delivery date", "refund amount", "contract "
|
| 453 |
+
"term", "manager name", "budget line"])
|
| 454 |
+
if has:
|
| 455 |
+
val = rng.choice(["12 days", "$" + str(rng.randint(50, 900)),
|
| 456 |
+
"24 months", "R. Alvarez",
|
| 457 |
+
"$" + str(rng.randint(2, 40)) + "k"])
|
| 458 |
+
st = (f"Ticket summary: customer requests escalation. The "
|
| 459 |
+
f"system record shows {field}: {val}. No other fields "
|
| 460 |
+
f"populated.")
|
| 461 |
+
correct = "present"
|
| 462 |
+
else:
|
| 463 |
+
st = (f"Ticket summary: customer requests escalation. No "
|
| 464 |
+
f"{field} is recorded anywhere in the record. Other "
|
| 465 |
+
f"fields are present.")
|
| 466 |
+
correct = "absent"
|
| 467 |
+
out.append(choice(st, f"Does the record state the {field}? Answer "
|
| 468 |
+
"only what the record contains.",
|
| 469 |
+
{"present": "The field is recorded",
|
| 470 |
+
"absent": "The field is not recorded",
|
| 471 |
+
"unclear": "Cannot be determined"},
|
| 472 |
+
correct, "jb_ambiguity"))
|
| 473 |
+
return out
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
# ---------------- severity ordinal ----------------
|
| 477 |
+
|
| 478 |
+
def gen_ordinal(n):
|
| 479 |
+
out = []
|
| 480 |
+
levels = {"sev_0": "No impact; cosmetic or documentation only",
|
| 481 |
+
"sev_1": "Minor impairment; workaround exists",
|
| 482 |
+
"sev_2": "Major impairment; core function degraded",
|
| 483 |
+
"sev_3": "Critical; outage, data loss, or safety risk"}
|
| 484 |
+
scen = [
|
| 485 |
+
("Typo in a settings label", "sev_0"),
|
| 486 |
+
("Button misaligned on mobile", "sev_0"),
|
| 487 |
+
("Search returns slow results but works", "sev_1"),
|
| 488 |
+
("PDF export missing images; copy-paste works", "sev_1"),
|
| 489 |
+
("Payment retries fail for a subset of users", "sev_2"),
|
| 490 |
+
("API returns 500s for one endpoint", "sev_2"),
|
| 491 |
+
("All users logged out, sessions unrecoverable", "sev_3"),
|
| 492 |
+
("Customer data corrupted in production", "sev_3"),
|
| 493 |
+
("Dashboard chart color wrong", "sev_0"),
|
| 494 |
+
("Login fails for users on one provider", "sev_2"),
|
| 495 |
+
("Docs page 404s", "sev_0"),
|
| 496 |
+
("Backup job delayed but completes", "sev_1"),
|
| 497 |
+
]
|
| 498 |
+
for _ in range(n):
|
| 499 |
+
desc, sev = rng.choice(scen)
|
| 500 |
+
# add distractor detail
|
| 501 |
+
extra = rng.choice(["Users reported it during peak hours.",
|
| 502 |
+
"One engineer could not reproduce it.",
|
| 503 |
+
"A customer mentioned it in a survey.",
|
| 504 |
+
"It appeared after the last deploy."])
|
| 505 |
+
st = f"Incident report: {desc}. {extra}"
|
| 506 |
+
out.append(choice(st, "Rate severity by the strict rubric; the "
|
| 507 |
+
"highest level that the facts support.",
|
| 508 |
+
dict(levels), sev, "jb_ordinal"))
|
| 509 |
+
return out
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
# ---------------- probability ----------------
|
| 513 |
+
|
| 514 |
+
def gen_probability(n):
|
| 515 |
+
out = []
|
| 516 |
+
for _ in range(n):
|
| 517 |
+
kind = rng.choice(["urn", "dice", "cards"])
|
| 518 |
+
if kind == "urn":
|
| 519 |
+
r_, b_ = rng.randint(2, 8), rng.randint(2, 8)
|
| 520 |
+
tot = r_ + b_
|
| 521 |
+
st = (f"An urn holds {r_} red and {b_} blue marbles. One marble "
|
| 522 |
+
f"is drawn uniformly at random.")
|
| 523 |
+
ans = r_ / tot
|
| 524 |
+
ds = [b_ / tot, 1 - ans, (r_ - 1) / max(tot - 1, 1)]
|
| 525 |
+
opts = [f"{ans:.3f}"] + [f"{d:.3f}" for d in ds]
|
| 526 |
+
q = "What is the probability the marble is red?"
|
| 527 |
+
elif kind == "dice":
|
| 528 |
+
k = rng.randint(2, 4)
|
| 529 |
+
faces = rng.choice([6, 8, 12, 20])
|
| 530 |
+
st = (f"A fair {faces}-sided die is rolled once.")
|
| 531 |
+
ans = k / faces
|
| 532 |
+
ds = [(k + 1) / faces, (k - 1) / faces if k > 1 else
|
| 533 |
+
(k + 2) / faces, 1 / faces]
|
| 534 |
+
opts = [f"{ans:.3f}"] + [f"{d:.3f}" for d in ds]
|
| 535 |
+
q = f"What is the probability the roll is {k} or less?"
|
| 536 |
+
else:
|
| 537 |
+
st = "A standard 52-card deck; one card is drawn."
|
| 538 |
+
ans = 13 / 52
|
| 539 |
+
ds = [1 / 52, 4 / 52, 26 / 52]
|
| 540 |
+
opts = [f"{ans:.3f}"] + [f"{d:.3f}" for d in ds]
|
| 541 |
+
q = "What is the probability the card is a heart?"
|
| 542 |
+
st += "\n\n" + q
|
| 543 |
+
keys = [f"p{i}" for i in range(4)]
|
| 544 |
+
order = list(range(4)); rng.shuffle(order)
|
| 545 |
+
crit = {keys[j]: opts[j] for j in order}
|
| 546 |
+
out.append(choice(st, "Choose the exact probability.", crit,
|
| 547 |
+
keys[order.index(0)], "jb_probability"))
|
| 548 |
+
return out
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
# ---------------- extraction verify (noul) ----------------
|
| 552 |
+
|
| 553 |
+
def gen_extract(n):
|
| 554 |
+
out = []
|
| 555 |
+
for _ in range(n):
|
| 556 |
+
name = rng.choice(["Invoice", "Ticket", "Form", "Record"])
|
| 557 |
+
f1 = rng.choice(["amount", "status", "owner", "date"])
|
| 558 |
+
v1 = rng.choice(["$" + str(rng.randint(10, 999)),
|
| 559 |
+
rng.choice(["open", "closed", "pending"]),
|
| 560 |
+
rng.choice(["team-a", "team-b", "ops"]),
|
| 561 |
+
f"2026-{rng.randint(1,12):02d}-{rng.randint(1,28):02d}"])
|
| 562 |
+
match = rng.random() < 0.5
|
| 563 |
+
claim_v = v1 if match else rng.choice(["$9999", "deleted",
|
| 564 |
+
"unknown", "1970-01-01"])
|
| 565 |
+
st = (f"{name} fields: {f1} = {v1}; priority = "
|
| 566 |
+
f"{rng.choice(['low','high'])}.\n\nClaim to verify: \"the "
|
| 567 |
+
f"{f1} is {claim_v}\".")
|
| 568 |
+
out.append(noul(st, "Decide whether the claim is supported by the "
|
| 569 |
+
"fields shown.", match, "jb_extract"))
|
| 570 |
+
return out
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
GENS = {
|
| 574 |
+
"intent": gen_intent,
|
| 575 |
+
"multihop": gen_multihop,
|
| 576 |
+
"temporal": gen_temporal,
|
| 577 |
+
"policy": gen_policy,
|
| 578 |
+
"trap": gen_trap,
|
| 579 |
+
"ambiguity": gen_ambiguity,
|
| 580 |
+
"ordinal": gen_ordinal,
|
| 581 |
+
"probability": gen_probability,
|
| 582 |
+
"extract": gen_extract,
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
def main():
|
| 587 |
+
ap = argparse.ArgumentParser()
|
| 588 |
+
ap.add_argument("--out", default="data/jb.jsonl")
|
| 589 |
+
ap.add_argument("--per", type=int, default=4000)
|
| 590 |
+
args = ap.parse_args()
|
| 591 |
+
rows = []
|
| 592 |
+
for name, fn in GENS.items():
|
| 593 |
+
got = fn(args.per)
|
| 594 |
+
print(name, len(got))
|
| 595 |
+
rows += got
|
| 596 |
+
rng.shuffle(rows)
|
| 597 |
+
with open(args.out, "w") as f:
|
| 598 |
+
for r in rows:
|
| 599 |
+
f.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 600 |
+
print("TOTAL", len(rows), "->", args.out)
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
if __name__ == "__main__":
|
| 604 |
+
main()
|