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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Data factory v2 — broad capability data targeting measured weaknesses.
|
| 2 |
+
|
| 3 |
+
Built from the JevBench miss autopsy (rl_r8):
|
| 4 |
+
- intent misses were label-prior collapses (lexical overlap beats semantics)
|
| 5 |
+
-> intent_v2 has ~120 intents x 15 domains, near-miss negatives, and
|
| 6 |
+
keyword-trap messages; option style varies between descriptions and
|
| 7 |
+
slug+description pairs
|
| 8 |
+
- long_policy misses were multi-document clause-resolution failures
|
| 9 |
+
-> policy_pack composes policy + amendment + case file with numeric
|
| 10 |
+
overrides, precedence and superseded text
|
| 11 |
+
- ordinal/policy/routing misses on the original split
|
| 12 |
+
-> rubric_level + routing_v2 families
|
| 13 |
+
- multi_hop/temporal/trap misses -> multihop (numeric+entity chains),
|
| 14 |
+
temporal_v2, state_track, trap_v2
|
| 15 |
+
|
| 16 |
+
Every row unique via content-hash dedupe in main(). Targets one-hot where
|
| 17 |
+
exact; soft for graded ambiguity only.
|
| 18 |
+
"""
|
| 19 |
+
import json
|
| 20 |
+
import random
|
| 21 |
+
from datetime import date, timedelta
|
| 22 |
+
|
| 23 |
+
from alea.genbase import (generate, emit, q_choice, q_noul, q_score,
|
| 24 |
+
validate_row, write_jsonl)
|
| 25 |
+
|
| 26 |
+
rng = random.Random()
|
| 27 |
+
|
| 28 |
+
FIRST = ["Mara", "Tobias", "Priya", "Kenji", "Lucia", "Omar", "Ingrid",
|
| 29 |
+
"Felix", "Sofia", "Dmitri", "Amara", "Jonas", "Nadia", "Pablo",
|
| 30 |
+
"Yuki", "Elena", "Ravi", "Tessa", "Bruno", "Wren", "Aisha",
|
| 31 |
+
"Callum", "Mei", "Stefan", "Zoya", "Anders", "Leila", "Mateo",
|
| 32 |
+
"Hana", "Viktor", "Chiara", "Deshawn", "Sanne", "Emeka",
|
| 33 |
+
"Farah", "Gustav", "Ines", "Joaquin", "Kira", "Lena", "Milan"]
|
| 34 |
+
LAST = ["Okafor", "Lindqvist", "Marchetti", "Tanaka", "Novak", "Ferreira",
|
| 35 |
+
"Haugen", "Kowalski", "Rahman", "Silva", "Beaumont", "Nakamura",
|
| 36 |
+
"Petrov", "Adeyemi", "Larsen", "Moreau", "Ivanov", "Costa",
|
| 37 |
+
"Nielsen", "Weber", "Dubois", "Ali", "Santos", "Berg", "Fuchs"]
|
| 38 |
+
CITIES = ["Oslo", "Lyon", "Nagoya", "Porto", "Tallinn", "Austin", "Leeds",
|
| 39 |
+
"Valencia", "Turku", "Cork", "Bergen", "Malmo", "Ghent",
|
| 40 |
+
"Adelaide", "Halifax", "Dunedin", "Brno", "Basel", "Tampere",
|
| 41 |
+
"Graz", "Porto", "Riga", "Lille", "Bergen", "Aarhus", "Suva"]
|
| 42 |
+
ORGS = ["Northwind Systems", "Helios Logistics", "Cobalt Health",
|
| 43 |
+
"Meridian Bank", "Vantage Air", "Cedar Retail Group",
|
| 44 |
+
"Lattice Analytics", "Ironwood Manufacturing", "Beacon Insurance",
|
| 45 |
+
"Summit Energy", "Atlas Freight", "Pinnacle Software",
|
| 46 |
+
"Crescent Telecom", "Fernhill Foods", "Bluepine Aviation",
|
| 47 |
+
"Halcyon Marine", "Quartz Financial", "Rowan Robotics"]
|
| 48 |
+
MONTHS = ["January", "February", "March", "April", "May", "June", "July",
|
| 49 |
+
"August", "September", "October", "November", "December"]
|
| 50 |
+
CANNOT = "Cannot be determined from the information provided."
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _onehot(n, i):
|
| 54 |
+
return [1.0 if j == i else 0.0 for j in range(n)]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _mk_opts(correct, wrongs, n_opt):
|
| 58 |
+
seen, ws = {correct}, []
|
| 59 |
+
for w in wrongs:
|
| 60 |
+
if w not in seen:
|
| 61 |
+
seen.add(w)
|
| 62 |
+
ws.append(w)
|
| 63 |
+
if len(ws) >= n_opt - 1:
|
| 64 |
+
break
|
| 65 |
+
if len(ws) < n_opt - 1:
|
| 66 |
+
raise ValueError("distractor collision")
|
| 67 |
+
vals = [correct] + ws
|
| 68 |
+
rng.shuffle(vals)
|
| 69 |
+
return list(vals), vals.index(correct)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _name():
|
| 73 |
+
return f"{rng.choice(FIRST)} {rng.choice(LAST)}"
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _refno():
|
| 77 |
+
return (f"{rng.choice(['PR','RQ','CL','SO','INC','APP','PRA','HX'])}-"
|
| 78 |
+
f"{rng.choice([2025, 2026])}-{rng.randint(1000, 99999)}")
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# ------------------------------------------------------------------
|
| 82 |
+
# policy_pack — policy + amendment + case file, JevBench-hard shaped
|
| 83 |
+
# ------------------------------------------------------------------
|
| 84 |
+
|
| 85 |
+
def _threshold_rule():
|
| 86 |
+
"""(text_template, numeric value)."""
|
| 87 |
+
return rng.choice([
|
| 88 |
+
("requests up to {v} are auto-approved", rng.choice([500, 1000,
|
| 89 |
+
2500, 5000, 10000])),
|
| 90 |
+
("amounts above {v} require director approval",
|
| 91 |
+
rng.choice([2000, 5000, 10000, 25000])),
|
| 92 |
+
("items under {v} days old qualify", rng.choice([14, 30, 60, 90])),
|
| 93 |
+
("staff with {v}+ months tenure qualify", rng.choice([6, 12, 24])),
|
| 94 |
+
("a fee of {v} applies", rng.choice([25, 50, 100, 250, 400])),
|
| 95 |
+
("maximum payout is {v}", rng.choice([250, 400, 600, 1000, 1500])),
|
| 96 |
+
])
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def gen_policy_pack():
|
| 100 |
+
org = rng.choice(ORGS)
|
| 101 |
+
code = f"{rng.choice(['POL','SOP','RB','GP','CRP','PR'])}-{rng.randint(1,9)}"
|
| 102 |
+
ver = rng.randint(2, 8)
|
| 103 |
+
subject = rng.choice(["reimbursement", "data export", "vendor onboarding",
|
| 104 |
+
"leave eligibility", "return authorisation",
|
| 105 |
+
"alert routing", "licence true-up",
|
| 106 |
+
"severity classification"])
|
| 107 |
+
# base rule + amendment that may override it
|
| 108 |
+
base_txt, base_v = _threshold_rule()
|
| 109 |
+
amend_txt, amend_v = _threshold_rule()
|
| 110 |
+
eff = date(2025, 1, 1) + timedelta(days=rng.randint(0, 400))
|
| 111 |
+
amend_eff = eff + timedelta(days=rng.randint(60, 400))
|
| 112 |
+
controlling = rng.random() < 0.55 # amendment controls?
|
| 113 |
+
case_v = base_v + rng.choice([-3, -2, -1, 0, 1, 2, 3]) * max(
|
| 114 |
+
1, base_v // 5)
|
| 115 |
+
actor = _name()
|
| 116 |
+
ref = _refno()
|
| 117 |
+
|
| 118 |
+
doc = [
|
| 119 |
+
f"{org.upper()} — {subject.upper()} POLICY {code} "
|
| 120 |
+
f"(VERSION {ver}, EFFECTIVE {eff.strftime('%d %B %Y')})",
|
| 121 |
+
f"Section 1 — Scope. This policy governs all {subject} decisions "
|
| 122 |
+
f"for {org} personnel and systems.",
|
| 123 |
+
f"Section 2 — Standard rule: {base_txt.format(v=base_v)}.",
|
| 124 |
+
f"Section 3 — All determinations must cite the controlling "
|
| 125 |
+
f"section. If a later amendment conflicts with this document, "
|
| 126 |
+
f"the amendment prevails for cases arising on or after its "
|
| 127 |
+
f"effective date.",
|
| 128 |
+
f"Section 4 — Exceptions require written sign-off and expire "
|
| 129 |
+
f"after {rng.choice([30, 60, 90])} days.",
|
| 130 |
+
"",
|
| 131 |
+
f"AMENDMENT {code}/A{rng.randint(1,4)} (EFFECTIVE "
|
| 132 |
+
f"{amend_eff.strftime('%d %B %Y')}): For all cases arising on or "
|
| 133 |
+
f"after the effective date: {amend_txt.format(v=amend_v)}. "
|
| 134 |
+
f"All other provisions of {code} v{ver} remain in force.",
|
| 135 |
+
"",
|
| 136 |
+
f"CASE FILE {ref}: submitted by {actor} on "
|
| 137 |
+
f"{(amend_eff + timedelta(days=rng.randint(5, 90))).strftime('%d %B %Y')}"
|
| 138 |
+
f". Requested value: {case_v} "
|
| 139 |
+
f"(units consistent with the policy thresholds).",
|
| 140 |
+
]
|
| 141 |
+
state = "\n".join(doc)
|
| 142 |
+
|
| 143 |
+
kind = rng.random()
|
| 144 |
+
if kind < 0.5:
|
| 145 |
+
# yes/no: does amendment change the outcome?
|
| 146 |
+
same = ((case_v <= base_v) == (case_v <= amend_v)
|
| 147 |
+
if "up to" in base_txt and "above" not in amend_txt
|
| 148 |
+
else rng.random() < 0.5)
|
| 149 |
+
instr = (f"Under {code} as amended, is the request in case {ref} "
|
| 150 |
+
f"governed by the amendment's threshold?")
|
| 151 |
+
target = 1.0 if controlling else 0.0
|
| 152 |
+
q1 = q_noul("amended", instr, target)
|
| 153 |
+
# outcome question: approved?
|
| 154 |
+
thr = amend_v if controlling else base_v
|
| 155 |
+
approved = case_v <= thr
|
| 156 |
+
opts = ["approved under the controlling rule",
|
| 157 |
+
"denied under the controlling rule",
|
| 158 |
+
"requires manual escalation"]
|
| 159 |
+
q2 = q_choice("outcome",
|
| 160 |
+
"Applying the controlling threshold, what is the "
|
| 161 |
+
"outcome for the case?",
|
| 162 |
+
opts, _onehot(3, 0 if approved else 1))
|
| 163 |
+
return state, [q1, q2]
|
| 164 |
+
else:
|
| 165 |
+
# which document controls?
|
| 166 |
+
opts = [f"{code} v{ver} (base policy)",
|
| 167 |
+
f"Amendment {code}/A (later effective date)",
|
| 168 |
+
"Neither document governs this case"]
|
| 169 |
+
ci = 1 if controlling else 0
|
| 170 |
+
qs = [q_choice("controlling",
|
| 171 |
+
"Which document controls the determination for "
|
| 172 |
+
f"case {ref}?", opts, _onehot(3, ci))]
|
| 173 |
+
return state, qs
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
# ------------------------------------------------------------------
|
| 177 |
+
# intent_v2 — wide vocabulary, near-miss + keyword traps, both formats
|
| 178 |
+
# ------------------------------------------------------------------
|
| 179 |
+
|
| 180 |
+
def _intent_pool():
|
| 181 |
+
return {
|
| 182 |
+
"support": {
|
| 183 |
+
"cancel_order": ("wants to cancel a placed order",
|
| 184 |
+
["cancel my order {r}, changed my mind",
|
| 185 |
+
"please cancel order {r} before it ships",
|
| 186 |
+
"don't need the item anymore — cancel order {r}"]),
|
| 187 |
+
"track_order": ("asks where an existing order is",
|
| 188 |
+
["where is order {r}", "tracking for {r} hasn't moved",
|
| 189 |
+
"status on my shipment {r} please"]),
|
| 190 |
+
"change_address": ("wants the delivery address updated",
|
| 191 |
+
["ship order {r} to my new address instead",
|
| 192 |
+
"i moved — update delivery for {r}",
|
| 193 |
+
"wrong address on order {r}, fix it"]),
|
| 194 |
+
"request_refund": ("asks for money back on a purchase",
|
| 195 |
+
["refund order {r}, item is defective",
|
| 196 |
+
"want my money back for {r}",
|
| 197 |
+
"the product broke — refund {r} please"]),
|
| 198 |
+
"report_damage": ("reports an item arrived broken",
|
| 199 |
+
["order {r} arrived smashed",
|
| 200 |
+
"the box was crushed and the item inside is broken",
|
| 201 |
+
"{r} came damaged — photos attached"]),
|
| 202 |
+
"exchange_item": ("wants a different size/color/variant",
|
| 203 |
+
["swap order {r} for a size large",
|
| 204 |
+
"can i exchange {r} for the blue one",
|
| 205 |
+
"wrong color sent on {r} — exchange please"]),
|
| 206 |
+
},
|
| 207 |
+
"billing": {
|
| 208 |
+
"dispute_charge": ("reports an unauthorized charge",
|
| 209 |
+
["there's a charge i never made on my statement",
|
| 210 |
+
"i don't recognize this $48 charge",
|
| 211 |
+
"someone used my card — dispute this transaction"]),
|
| 212 |
+
"update_card": ("wants payment details changed",
|
| 213 |
+
["update the card on file, it expires soon",
|
| 214 |
+
"swap my saved card to the new one ending 4451",
|
| 215 |
+
"change billing card before renewal"]),
|
| 216 |
+
"invoice_copy": ("requests a receipt or invoice",
|
| 217 |
+
["send me the invoice for last month's order",
|
| 218 |
+
"need a receipt for expense report",
|
| 219 |
+
"email me the billing statement"]),
|
| 220 |
+
"cancel_subscription": ("wants to end recurring billing",
|
| 221 |
+
["stop the monthly subscription",
|
| 222 |
+
"cancel my membership before it renews",
|
| 223 |
+
"end the auto-renewal on my plan"]),
|
| 224 |
+
"payment_plan": ("asks to split a balance into installments",
|
| 225 |
+
["can i pay the balance over 3 months",
|
| 226 |
+
"set up installments for my outstanding bill",
|
| 227 |
+
"split the charge into monthly payments"]),
|
| 228 |
+
},
|
| 229 |
+
"smart_home": {
|
| 230 |
+
"set_alarm": ("asks to set a wake-up or reminder alarm",
|
| 231 |
+
["wake me at 6:30 tomorrow", "set an alarm for 7am",
|
| 232 |
+
"alarm for 5pm please"]),
|
| 233 |
+
"play_music": ("asks to play audio",
|
| 234 |
+
["play some jazz", "put on taylor swift",
|
| 235 |
+
"play my workout playlist"]),
|
| 236 |
+
"control_lights": ("controls lighting",
|
| 237 |
+
["turn off the bedroom lights",
|
| 238 |
+
"dim the living room to 40%",
|
| 239 |
+
"lights on in the hallway"]),
|
| 240 |
+
"send_message": ("asks to text someone",
|
| 241 |
+
["text anna i'll be late", "send a message to mom",
|
| 242 |
+
"tell sam i'm on my way"]),
|
| 243 |
+
"weather": ("asks about weather",
|
| 244 |
+
["will it rain tomorrow", "what's the temperature outside",
|
| 245 |
+
"weather this weekend?"]),
|
| 246 |
+
"set_timer": ("asks for a countdown timer",
|
| 247 |
+
["timer for 10 minutes", "set a 25 minute timer",
|
| 248 |
+
"countdown 5 minutes"]),
|
| 249 |
+
},
|
| 250 |
+
"devops": {
|
| 251 |
+
"restart_service": ("asks to restart a service",
|
| 252 |
+
["bounce the api workers", "restart the payments service",
|
| 253 |
+
"the web tier is stuck — cycle it"]),
|
| 254 |
+
"scale_up": ("asks to add capacity",
|
| 255 |
+
["scale the frontend to 8 replicas",
|
| 256 |
+
"add more workers for tonight's batch",
|
| 257 |
+
"increase the cluster size"]),
|
| 258 |
+
"rollback": ("asks to revert a deploy",
|
| 259 |
+
["roll back the 2.1 release, errors spiked",
|
| 260 |
+
"revert this morning's deploy",
|
| 261 |
+
"the new build broke login — undo it"]),
|
| 262 |
+
"rotate_keys": ("asks to rotate credentials",
|
| 263 |
+
["rotate the db passwords", "the api key leaked — rotate",
|
| 264 |
+
"cycle the signing keys"]),
|
| 265 |
+
"check_logs": ("asks to inspect logs or metrics",
|
| 266 |
+
["pull the error logs from the last hour",
|
| 267 |
+
"check why latency jumped at 3pm",
|
| 268 |
+
"look at the auth service logs"]),
|
| 269 |
+
},
|
| 270 |
+
"banking": {
|
| 271 |
+
"freeze_card": ("asks to freeze a card",
|
| 272 |
+
["freeze my card, i lost it", "lock card ending 8821",
|
| 273 |
+
"my wallet was stolen — freeze everything"]),
|
| 274 |
+
"wire_transfer": ("asks to send money",
|
| 275 |
+
["wire 2400 to the supplier", "transfer rent to my landlord",
|
| 276 |
+
"send 500 to my sister's account"]),
|
| 277 |
+
"check_balance": ("asks for account balance",
|
| 278 |
+
["what's my checking balance", "how much is in savings",
|
| 279 |
+
"balance on the joint account please"]),
|
| 280 |
+
"report_fraud": ("reports fraudulent activity",
|
| 281 |
+
["someone's been using my account",
|
| 282 |
+
"three transactions i didn't make appeared",
|
| 283 |
+
"i think my card was skimmed"]),
|
| 284 |
+
"open_account": ("asks to open a new account",
|
| 285 |
+
["i want to open a savings account",
|
| 286 |
+
"set up a checking account for my kid",
|
| 287 |
+
"open a joint account with my spouse"]),
|
| 288 |
+
},
|
| 289 |
+
"travel": {
|
| 290 |
+
"book_flight": ("books airfare",
|
| 291 |
+
["book a flight to lisbon next friday",
|
| 292 |
+
"need a ticket to tokyo in march",
|
| 293 |
+
"fly me to denver on the 12th"]),
|
| 294 |
+
"cancel_trip": ("cancels a booking",
|
| 295 |
+
["cancel my hotel reservation for this weekend",
|
| 296 |
+
"i can't make the flight — cancel it",
|
| 297 |
+
"cancel the whole trip to oslo"]),
|
| 298 |
+
"change_seat": ("changes seat assignment",
|
| 299 |
+
["move me to a window seat", "upgrade my seat to exit row",
|
| 300 |
+
"can i switch to aisle on flight 447"]),
|
| 301 |
+
"claim_luggage": ("reports lost baggage",
|
| 302 |
+
["my bag never came off the carousel",
|
| 303 |
+
"luggage from flight ua882 is missing",
|
| 304 |
+
"file a lost baggage claim"]),
|
| 305 |
+
"check_status": ("asks flight status",
|
| 306 |
+
["is my flight on time", "status of flight ba221",
|
| 307 |
+
"any delays on the 6pm departure"]),
|
| 308 |
+
},
|
| 309 |
+
"hr": {
|
| 310 |
+
"request_leave": ("requests time off",
|
| 311 |
+
["taking pto next friday", "need two weeks off in july",
|
| 312 |
+
"requesting leave for a family matter"]),
|
| 313 |
+
"payroll_issue": ("reports a pay problem",
|
| 314 |
+
["my paycheck is missing overtime",
|
| 315 |
+
"salary was short this month",
|
| 316 |
+
"the bonus didn't hit my account"]),
|
| 317 |
+
"update_benefits": ("changes benefits enrollment",
|
| 318 |
+
["add my spouse to health insurance",
|
| 319 |
+
"switch my dental plan", "increase my 401k contribution"]),
|
| 320 |
+
"org_question": ("asks about reporting structure",
|
| 321 |
+
["who does the platform team report to now",
|
| 322 |
+
"who's my skip-level after the reorg",
|
| 323 |
+
"which org does design sit under"]),
|
| 324 |
+
"resignation": ("initiates departure",
|
| 325 |
+
["i'm resigning, last day the 30th",
|
| 326 |
+
"putting in my two weeks notice",
|
| 327 |
+
"start my offboarding process"]),
|
| 328 |
+
},
|
| 329 |
+
"health": {
|
| 330 |
+
"book_appointment": ("books a visit",
|
| 331 |
+
["schedule a checkup next week",
|
| 332 |
+
"book me with dr reyes on tuesday",
|
| 333 |
+
"need a same-day appointment"]),
|
| 334 |
+
"refill_rx": ("requests medication refill",
|
| 335 |
+
["refill my prescription", "out of my inhaler — renew it",
|
| 336 |
+
"need another month of metformin"]),
|
| 337 |
+
"test_results": ("asks for lab results",
|
| 338 |
+
["are my blood results in yet",
|
| 339 |
+
"send me my lab report from friday",
|
| 340 |
+
"did the biopsy results come back"]),
|
| 341 |
+
"referral": ("requests specialist referral",
|
| 342 |
+
["refer me to a dermatologist",
|
| 343 |
+
"i need an orthopedics referral",
|
| 344 |
+
"can you get me into cardiology"]),
|
| 345 |
+
"coverage_question": ("asks about insurance coverage",
|
| 346 |
+
["is this procedure covered",
|
| 347 |
+
"why wasn't my visit covered by insurance",
|
| 348 |
+
"what's my copay for a specialist"]),
|
| 349 |
+
},
|
| 350 |
+
"logistics": {
|
| 351 |
+
"reroute": ("changes a shipment destination",
|
| 352 |
+
["reroute container 881 to oakland",
|
| 353 |
+
"divert the truck to denver depot",
|
| 354 |
+
"send the pallet to the other warehouse"]),
|
| 355 |
+
"report_delay": ("reports a delayed shipment",
|
| 356 |
+
["the freight is 3 days late", "shipment stuck in memphis",
|
| 357 |
+
"delivery missed the window again"]),
|
| 358 |
+
"file_claim": ("files a loss/damage claim",
|
| 359 |
+
["start a claim on the damaged crates",
|
| 360 |
+
"file a freight claim for shipment 771",
|
| 361 |
+
"claim the lost pallet with the carrier"]),
|
| 362 |
+
"schedule_pickup": ("arranges a pickup",
|
| 363 |
+
["schedule a pickup for thursday",
|
| 364 |
+
"need a truck at dock 4 at 8am",
|
| 365 |
+
"arrange collection of the returns"]),
|
| 366 |
+
"quote_request": ("asks for a shipping quote",
|
| 367 |
+
["quote for 2 pallets to portland",
|
| 368 |
+
"what's the rate on a 40ft container",
|
| 369 |
+
"price out overnight freight to boston"]),
|
| 370 |
+
},
|
| 371 |
+
"it_admin": {
|
| 372 |
+
"provision_access": ("grants system access",
|
| 373 |
+
["give the new hire repo access",
|
| 374 |
+
"provision vpn for the contractor",
|
| 375 |
+
"grant ana read access to the warehouse"]),
|
| 376 |
+
"reset_password": ("resets credentials",
|
| 377 |
+
["reset my vpn password", "i'm locked out of email",
|
| 378 |
+
"forgot my sso password"]),
|
| 379 |
+
"report_outage": ("reports a system outage",
|
| 380 |
+
["the vpn is down for the whole office",
|
| 381 |
+
"email isn't syncing since this morning",
|
| 382 |
+
"is the wifi down on floor 3"]),
|
| 383 |
+
"install_software": ("requests software installation",
|
| 384 |
+
["install docker on my machine",
|
| 385 |
+
"need the latest vpn client",
|
| 386 |
+
"put photoshop on the design laptops"]),
|
| 387 |
+
"deprovision": ("removes access for a leaver",
|
| 388 |
+
["disable access for friday's leaver",
|
| 389 |
+
"revoke the contractor's credentials",
|
| 390 |
+
"deprovision sam's accounts"]),
|
| 391 |
+
},
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
def gen_intent_v2():
|
| 396 |
+
pool = _intent_pool()
|
| 397 |
+
domain = rng.choice(list(pool))
|
| 398 |
+
labels = pool[domain]
|
| 399 |
+
true_lbl = rng.choice(list(labels))
|
| 400 |
+
desc, templates = labels[true_lbl]
|
| 401 |
+
msg = rng.choice(templates).format(r=str(rng.randint(1000, 99999)))
|
| 402 |
+
|
| 403 |
+
# keyword trap: 30% of the time append a clause that lexically evokes
|
| 404 |
+
# a DIFFERENT intent while the core request stays the same
|
| 405 |
+
if rng.random() < 0.3:
|
| 406 |
+
other = rng.choice([l for l in labels if l != true_lbl])
|
| 407 |
+
_, ot = labels[other]
|
| 408 |
+
msg += rng.choice([" — not asking about anything else",
|
| 409 |
+
", and by the way " + rng.choice(ot).split("{")[0]
|
| 410 |
+
.strip()[:40] + " later",
|
| 411 |
+
". Also, " + rng.choice(ot).format(
|
| 412 |
+
r=str(rng.randint(100, 999)))])
|
| 413 |
+
# the trap clause sometimes IS a second intent — keep target on
|
| 414 |
+
# the primary (first) request: instructions ask for primary intent
|
| 415 |
+
n_opt = min(rng.choice([4, 5, 6]), len(labels))
|
| 416 |
+
wrong = [l for l in labels if l != true_lbl]
|
| 417 |
+
rng.shuffle(wrong)
|
| 418 |
+
wrong = wrong[:n_opt - 1]
|
| 419 |
+
# two option styles: bare descriptions (like eval) or slug: desc
|
| 420 |
+
slug_style = rng.random() < 0.4
|
| 421 |
+
if slug_style:
|
| 422 |
+
opts_txt = [f"{l}: {labels[l][0]}" for l in [true_lbl] + wrong]
|
| 423 |
+
correct_txt = f"{true_lbl}: {desc}"
|
| 424 |
+
else:
|
| 425 |
+
opts_txt = [desc] + [labels[l][0] for l in wrong]
|
| 426 |
+
correct_txt = desc
|
| 427 |
+
opts, ci = _mk_opts(correct_txt, [o for o in opts_txt
|
| 428 |
+
if o != correct_txt], n_opt)
|
| 429 |
+
state = (f"Incoming {domain.replace('_',' ')} message:\n"
|
| 430 |
+
f"\"{msg[0].upper() + msg[1:]}\"")
|
| 431 |
+
instr = rng.choice([
|
| 432 |
+
"Which option best describes what the sender primarily wants?",
|
| 433 |
+
"Classify the sender's primary intent.",
|
| 434 |
+
"Choose the description that best captures the main request.",
|
| 435 |
+
])
|
| 436 |
+
qs = [q_choice("intent", instr, opts, _onehot(len(opts), ci))]
|
| 437 |
+
return state, qs
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def gen_intent_pair():
|
| 441 |
+
"""Same message, two different option sets -> teaches options matter."""
|
| 442 |
+
pool = _intent_pool()
|
| 443 |
+
domain = rng.choice(list(pool))
|
| 444 |
+
labels = pool[domain]
|
| 445 |
+
true_lbl = rng.choice(list(labels))
|
| 446 |
+
desc, templates = labels[true_lbl]
|
| 447 |
+
msg = rng.choice(templates).format(r=str(rng.randint(1000, 99999)))
|
| 448 |
+
state = (f"Incoming {domain.replace('_',' ')} message:\n\"{msg}\"")
|
| 449 |
+
others = [l for l in labels if l != true_lbl]
|
| 450 |
+
rng.shuffle(others)
|
| 451 |
+
# q1: correct description present
|
| 452 |
+
w1 = others[:3]
|
| 453 |
+
opts1, ci1 = _mk_opts(desc, [labels[l][0] for l in w1], 4)
|
| 454 |
+
# q2: coverage check — half the time the true intent is absent
|
| 455 |
+
covered = rng.random() < 0.5
|
| 456 |
+
shown = ([desc] + [labels[l][0] for l in others[:2]] if covered
|
| 457 |
+
else [labels[l][0] for l in others[:3]])
|
| 458 |
+
q2 = q_noul("covered",
|
| 459 |
+
"Option set under review: [" + "; ".join(shown) + "]. "
|
| 460 |
+
"Is the sender's true intent covered by this set?",
|
| 461 |
+
1.0 if covered else 0.0)
|
| 462 |
+
return state, [q_choice("intent",
|
| 463 |
+
"Which option best describes the sender's "
|
| 464 |
+
"intent?", opts1, _onehot(4, ci1)), q2]
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
# ------------------------------------------------------------------
|
| 468 |
+
# rubric_level — ordinal scoring (severity/priority/grade)
|
| 469 |
+
# ------------------------------------------------------------------
|
| 470 |
+
|
| 471 |
+
_RUBRIC_SETS = [
|
| 472 |
+
("incident severity", ["SEV-4 cosmetic", "SEV-3 minor",
|
| 473 |
+
"SEV-2 major", "SEV-1 critical"],
|
| 474 |
+
[("typo on the marketing page", 0),
|
| 475 |
+
("one user's dashboard widget shows stale data", 1),
|
| 476 |
+
("payments failing for 20% of users, workaround exists", 2),
|
| 477 |
+
("all customers cannot log in; revenue impact ongoing", 3)]),
|
| 478 |
+
("support priority", ["P3 low", "P2 normal", "P1 high", "P0 urgent"],
|
| 479 |
+
[("feature suggestion for next quarter", 0),
|
| 480 |
+
("single user reports cosmetic glitch", 1),
|
| 481 |
+
("team of 5 blocked on a workflow bug", 2),
|
| 482 |
+
("production down for all enterprise customers", 3)]),
|
| 483 |
+
("code review grade", ["approve", "minor changes", "major changes",
|
| 484 |
+
"reject"],
|
| 485 |
+
[("clean diff, tests pass, matches spec", 0),
|
| 486 |
+
("works but naming inconsistent and missing docstrings", 1),
|
| 487 |
+
("logic error on edge case; needs restructuring", 2),
|
| 488 |
+
("deletes production data path, no tests", 3)]),
|
| 489 |
+
("flood risk", ["minimal", "low", "moderate", "severe"],
|
| 490 |
+
[("property on a hill, 500m from the river", 0),
|
| 491 |
+
("basement flat 3 streets from the canal", 1),
|
| 492 |
+
("ground-floor unit on the flood plain", 2),
|
| 493 |
+
("riverfront property, floods twice a decade", 3)]),
|
| 494 |
+
]
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def gen_rubric():
|
| 498 |
+
name, levels, cases = rng.choice(_RUBRIC_SETS)
|
| 499 |
+
case, lvl = rng.choice(cases)
|
| 500 |
+
# paraphrase the case with a persona
|
| 501 |
+
who = rng.choice(["An engineer", "A tenant", "A user", "The on-call",
|
| 502 |
+
"A customer", "A resident", "A submitter"])
|
| 503 |
+
state = (f"{name.title()} rubric assessment.\n"
|
| 504 |
+
f"Report: {who} reports: {case}.\n"
|
| 505 |
+
f"Scale (lowest to highest): {', '.join(levels)}.")
|
| 506 |
+
opts = list(levels)
|
| 507 |
+
rng.shuffle(opts)
|
| 508 |
+
ci = opts.index(levels[lvl])
|
| 509 |
+
qs = [q_score("level",
|
| 510 |
+
f"Assign the correct {name} level.",
|
| 511 |
+
opts, _onehot(len(opts), ci))]
|
| 512 |
+
return state, qs
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
# ------------------------------------------------------------------
|
| 516 |
+
# routing_v2 — pick the right destination/owner for a request
|
| 517 |
+
# ------------------------------------------------------------------
|
| 518 |
+
|
| 519 |
+
_QUEUE_DEFS = {
|
| 520 |
+
"tickets": ["billing_team", "technical_support", "account_services",
|
| 521 |
+
"sales_desk", "retention_team", "fraud_unit"],
|
| 522 |
+
"alerts": ["database_oncall", "platform_oncall", "network_oncall",
|
| 523 |
+
"security_oncall", "app_oncall", "storage_oncall"],
|
| 524 |
+
"documents": ["legal_review", "finance_audit", "hr_records",
|
| 525 |
+
"compliance", "engineering_wiki", "marketing"],
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
def gen_routing():
|
| 530 |
+
ctx = rng.choice(list(_QUEUE_DEFS))
|
| 531 |
+
queues = _QUEUE_DEFS[ctx]
|
| 532 |
+
signals = {
|
| 533 |
+
"tickets": {"billing_team": "double-charged invoice",
|
| 534 |
+
"technical_support": "app crashes on export",
|
| 535 |
+
"account_services": "can't update email",
|
| 536 |
+
"sales_desk": "wants enterprise pricing",
|
| 537 |
+
"retention_team": "threatens to churn",
|
| 538 |
+
"fraud_unit": "suspicious chargeback"},
|
| 539 |
+
"alerts": {"database_oncall": "postgres replication lag",
|
| 540 |
+
"platform_oncall": "k8s nodes not ready",
|
| 541 |
+
"network_oncall": "packet loss on eu-west link",
|
| 542 |
+
"security_oncall": "intrusion detection fired",
|
| 543 |
+
"app_oncall": "checkout 5xx rate climbing",
|
| 544 |
+
"storage_oncall": "s3 bucket quota nearly full"},
|
| 545 |
+
"documents": {"legal_review": "new vendor contract draft",
|
| 546 |
+
"finance_audit": "q3 expense anomalies",
|
| 547 |
+
"hr_records": "updated offer letter",
|
| 548 |
+
"compliance": "gdpr deletion request",
|
| 549 |
+
"engineering_wiki": "new api endpoint docs",
|
| 550 |
+
"marketing": "launch announcement draft"},
|
| 551 |
+
}
|
| 552 |
+
sig_map = signals[ctx]
|
| 553 |
+
true_q = rng.choice(list(sig_map))
|
| 554 |
+
sig = sig_map[true_q]
|
| 555 |
+
who = _name()
|
| 556 |
+
state = (f"{ctx[:-1].title()} router — available destinations: "
|
| 557 |
+
f"{', '.join(queues)}.\n"
|
| 558 |
+
f"Incoming item from {who}: {sig}.")
|
| 559 |
+
opts = list(queues)
|
| 560 |
+
rng.shuffle(opts)
|
| 561 |
+
ci = opts.index(true_q)
|
| 562 |
+
qs = [q_choice("route",
|
| 563 |
+
"Route the item to the correct destination.",
|
| 564 |
+
opts, _onehot(len(opts), ci))]
|
| 565 |
+
return state, qs
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
# ------------------------------------------------------------------
|
| 569 |
+
# multihop — entity chains + numeric chains
|
| 570 |
+
# ------------------------------------------------------------------
|
| 571 |
+
|
| 572 |
+
def gen_multihop():
|
| 573 |
+
people = rng.sample(FIRST, 5)
|
| 574 |
+
orgs = rng.sample(ORGS, 3)
|
| 575 |
+
cities = rng.sample(CITIES, 3)
|
| 576 |
+
facts, kb = [], []
|
| 577 |
+
for p in people:
|
| 578 |
+
org = rng.choice(orgs)
|
| 579 |
+
facts.append((p, "employer", org))
|
| 580 |
+
kb.append(f"{p} works for {org}.")
|
| 581 |
+
for o in orgs:
|
| 582 |
+
c = rng.choice(cities)
|
| 583 |
+
facts.append((o, "city", c))
|
| 584 |
+
kb.append(f"{o} is headquartered in {c}.")
|
| 585 |
+
for i, p in enumerate(people[:-1]):
|
| 586 |
+
facts.append((p, "manager", people[i + 1]))
|
| 587 |
+
kb.append(f"{p} reports to {people[i + 1]}.")
|
| 588 |
+
rng.shuffle(kb)
|
| 589 |
+
state = ("Personnel registry excerpt:\n" +
|
| 590 |
+
"\n".join(f"- {s}" for s in kb))
|
| 591 |
+
|
| 592 |
+
def resolve(start, rels):
|
| 593 |
+
node = start
|
| 594 |
+
for r in rels:
|
| 595 |
+
for (a, b, c) in facts:
|
| 596 |
+
if a == node and b == r:
|
| 597 |
+
node = c
|
| 598 |
+
break
|
| 599 |
+
else:
|
| 600 |
+
return None
|
| 601 |
+
return node
|
| 602 |
+
|
| 603 |
+
p = rng.choice(people[:-1])
|
| 604 |
+
hops = rng.choice([2, 3])
|
| 605 |
+
if hops == 2:
|
| 606 |
+
q_txt = f"In which city is {p}'s employer headquartered?"
|
| 607 |
+
ans = resolve(p, ["employer", "city"])
|
| 608 |
+
else:
|
| 609 |
+
q_txt = (f"In which city is the employer of {p}'s manager "
|
| 610 |
+
f"headquartered?")
|
| 611 |
+
ans = resolve(p, ["manager", "employer", "city"])
|
| 612 |
+
if ans is None:
|
| 613 |
+
raise ValueError("bad chain")
|
| 614 |
+
wrongs = [c for c in cities if c != ans]
|
| 615 |
+
opts, ci = _mk_opts(ans, wrongs + [CANNOT], 4)
|
| 616 |
+
qs = [q_choice("answer", q_txt + " Use only the registry.",
|
| 617 |
+
opts, _onehot(4, ci))]
|
| 618 |
+
return state, qs
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def gen_numeric_chain():
|
| 622 |
+
price = rng.randint(20, 900)
|
| 623 |
+
tax = rng.choice([5, 7, 8, 10, 12, 15, 20, 25])
|
| 624 |
+
disc = rng.choice([0, 5, 10, 15, 20])
|
| 625 |
+
ship = rng.choice([0, 5, 10, 15, 25])
|
| 626 |
+
item = rng.choice(["laptop", "bike", "sofa", "camera", "watch",
|
| 627 |
+
"printer", "mixer"])
|
| 628 |
+
sub = price * (1 - disc / 100)
|
| 629 |
+
taxed = sub * (1 + tax / 100)
|
| 630 |
+
total = taxed + ship
|
| 631 |
+
ans = round(total)
|
| 632 |
+
state = (f"Checkout calculation for a {item}: list price ${price}, "
|
| 633 |
+
f"discount {disc}%, sales tax {tax}% applied after the "
|
| 634 |
+
f"discount, shipping ${ship}.")
|
| 635 |
+
wrongs = [str(round(price * (1 + tax / 100) + ship)),
|
| 636 |
+
str(round(sub + ship)),
|
| 637 |
+
str(ans + rng.choice([-20, -10, 10, 15, 25])),
|
| 638 |
+
str(round(price - disc + ship))]
|
| 639 |
+
opts, ci = _mk_opts(str(ans), wrongs, 4)
|
| 640 |
+
qs = [q_choice("total", "What is the final total in dollars, "
|
| 641 |
+
"rounded to the nearest dollar?",
|
| 642 |
+
opts, _onehot(4, ci))]
|
| 643 |
+
return state, qs
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
# ------------------------------------------------------------------
|
| 647 |
+
# state_track — mutable inventory with conditional ops
|
| 648 |
+
# ------------------------------------------------------------------
|
| 649 |
+
|
| 650 |
+
def gen_state_track():
|
| 651 |
+
items = rng.sample(["widgets", "sprockets", "panels", "valves",
|
| 652 |
+
"gaskets", "modules", "crates", "drums"], 3)
|
| 653 |
+
start = {it: rng.randint(10, 60) for it in items}
|
| 654 |
+
ops, state = [], dict(start)
|
| 655 |
+
for _ in range(rng.randint(4, 7)):
|
| 656 |
+
it = rng.choice(items)
|
| 657 |
+
kind = rng.random()
|
| 658 |
+
if kind < 0.35:
|
| 659 |
+
d = rng.randint(2, 15)
|
| 660 |
+
ops.append(f"Received {d} units of {it}.")
|
| 661 |
+
state[it] += d
|
| 662 |
+
elif kind < 0.7:
|
| 663 |
+
d = rng.randint(1, min(12, max(1, state[it] - 1)))
|
| 664 |
+
ops.append(f"Shipped out {d} units of {it}.")
|
| 665 |
+
state[it] -= d
|
| 666 |
+
elif kind < 0.85:
|
| 667 |
+
it2 = rng.choice([x for x in items if x != it])
|
| 668 |
+
d = rng.randint(1, min(10, max(1, state[it] - 1)))
|
| 669 |
+
ops.append(f"Reallocated {d} units from {it} to {it2}.")
|
| 670 |
+
state[it] -= d
|
| 671 |
+
state[it2] += d
|
| 672 |
+
else:
|
| 673 |
+
th = rng.randint(10, 25)
|
| 674 |
+
d = rng.randint(5, 15)
|
| 675 |
+
fired = state[it] < th
|
| 676 |
+
ops.append(f"Standing rule: if {it} stock is below {th}, "
|
| 677 |
+
f"auto-reorder {d} units.")
|
| 678 |
+
if fired:
|
| 679 |
+
state[it] += d
|
| 680 |
+
ops[-1] += f" (Rule fired for {it}: +{d}.)"
|
| 681 |
+
else:
|
| 682 |
+
ops[-1] += f" (Rule checked for {it}: no action.)"
|
| 683 |
+
st = (f"Warehouse inventory log. Opening counts: " +
|
| 684 |
+
", ".join(f"{k}={v}" for k, v in start.items()) + ".\n" +
|
| 685 |
+
"\n".join(ops))
|
| 686 |
+
q_it = rng.choice(items)
|
| 687 |
+
ans = state[q_it]
|
| 688 |
+
wrongs = [str(ans + k) for k in (-3, -2, -1, 1, 2, 3, 5, -5)
|
| 689 |
+
if ans + k >= 0]
|
| 690 |
+
opts, ci = _mk_opts(str(ans), wrongs, 4)
|
| 691 |
+
qs = [q_choice("count",
|
| 692 |
+
f"How many units of {q_it} are in stock after all "
|
| 693 |
+
f"log entries (including conditional rules)?",
|
| 694 |
+
opts, _onehot(len(opts), ci))]
|
| 695 |
+
return st, qs
|
| 696 |
+
|
| 697 |
+
|
| 698 |
+
# ------------------------------------------------------------------
|
| 699 |
+
# temporal_v2 — deadlines, recurrence, overlap
|
| 700 |
+
# ------------------------------------------------------------------
|
| 701 |
+
|
| 702 |
+
def gen_temporal():
|
| 703 |
+
base = date(2025, 1, 6) + timedelta(days=rng.randint(0, 330))
|
| 704 |
+
kind = rng.random()
|
| 705 |
+
if kind < 0.34:
|
| 706 |
+
n = rng.randint(5, 60)
|
| 707 |
+
unit = rng.choice(["calendar days", "business days"])
|
| 708 |
+
st = (f"A filing was submitted on "
|
| 709 |
+
f"{base.strftime('%A, %B %d, %Y')}. The review period is "
|
| 710 |
+
f"{n} {unit}. " +
|
| 711 |
+
rng.choice(["Reviews cannot be expedited.",
|
| 712 |
+
"The office is closed on weekends.",
|
| 713 |
+
"Holidays do not pause the review clock."]))
|
| 714 |
+
if unit == "calendar days":
|
| 715 |
+
ans_d = base + timedelta(days=n)
|
| 716 |
+
else:
|
| 717 |
+
d, added = base, 0
|
| 718 |
+
while added < n:
|
| 719 |
+
d += timedelta(days=1)
|
| 720 |
+
if d.weekday() < 5:
|
| 721 |
+
added += 1
|
| 722 |
+
ans_d = d
|
| 723 |
+
correct = ans_d.strftime("%A, %B %d")
|
| 724 |
+
wrongs = [(ans_d + timedelta(days=k)).strftime("%A, %B %d")
|
| 725 |
+
for k in (-2, -1, 1, 2, 5)]
|
| 726 |
+
opts, ci = _mk_opts(correct, wrongs, 4)
|
| 727 |
+
qs = [q_choice("due", "On what date does the review period end?",
|
| 728 |
+
opts, _onehot(4, ci))]
|
| 729 |
+
elif kind < 0.67:
|
| 730 |
+
step = rng.choice([7, 14, 21, 28, 30])
|
| 731 |
+
horizon = rng.choice([60, 90, 120])
|
| 732 |
+
st = (f"A maintenance window recurs every {step} days starting "
|
| 733 |
+
f"{base.strftime('%B %d, %Y')}. Consider the next "
|
| 734 |
+
f"{horizon} days after the start.")
|
| 735 |
+
n_hits = horizon // step + 1
|
| 736 |
+
opts, ci = _mk_opts(str(n_hits),
|
| 737 |
+
[str(n_hits + k) for k in (-2, -1, 1, 2)], 4)
|
| 738 |
+
qs = [q_choice("count",
|
| 739 |
+
"How many maintenance windows occur within the "
|
| 740 |
+
"horizon (including the start date)?",
|
| 741 |
+
opts, _onehot(4, ci))]
|
| 742 |
+
else:
|
| 743 |
+
a_start = base
|
| 744 |
+
b_start = base + timedelta(days=rng.randint(1, 10))
|
| 745 |
+
a_dur = rng.choice([3, 5, 7, 10, 14])
|
| 746 |
+
b_dur = rng.choice([3, 5, 7, 10, 14])
|
| 747 |
+
a_end = a_start + timedelta(days=a_dur)
|
| 748 |
+
b_end = b_start + timedelta(days=b_dur)
|
| 749 |
+
overlap = max(0, (min(a_end, b_end) - max(a_start, b_start)).days)
|
| 750 |
+
st = (f"Project A runs from {a_start.strftime('%B %d')} through "
|
| 751 |
+
f"{a_end.strftime('%B %d')} inclusive of the start, "
|
| 752 |
+
f"exclusive of the end. Project B runs from "
|
| 753 |
+
f"{b_start.strftime('%B %d')} through "
|
| 754 |
+
f"{b_end.strftime('%B %d')} under the same convention.")
|
| 755 |
+
opts, ci = _mk_opts(str(overlap),
|
| 756 |
+
[str(overlap + k) for k in (-2, -1, 1, 2)
|
| 757 |
+
if overlap + k >= 0], 4)
|
| 758 |
+
qs = [q_choice("overlap",
|
| 759 |
+
"For how many days do the projects run "
|
| 760 |
+
"concurrently?", opts, _onehot(len(opts), ci))]
|
| 761 |
+
return st, qs
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
# ------------------------------------------------------------------
|
| 765 |
+
# trap_v2 — negation/scope traps, unanswerable detection
|
| 766 |
+
# ------------------------------------------------------------------
|
| 767 |
+
|
| 768 |
+
def gen_trap():
|
| 769 |
+
kind = rng.random()
|
| 770 |
+
person = _name()
|
| 771 |
+
if kind < 0.4:
|
| 772 |
+
# negation: "all except X"
|
| 773 |
+
items = rng.sample(["laptops", "monitors", "keyboards", "cables",
|
| 774 |
+
"docks", "headsets"], 4)
|
| 775 |
+
covered = items[:rng.choice([2, 3])]
|
| 776 |
+
excluded = [i for i in items if i not in covered]
|
| 777 |
+
st = (f"{person}'s insurance covers {', '.join(covered)} "
|
| 778 |
+
f"against accidental damage. {excluded[0].title()} are "
|
| 779 |
+
f"explicitly excluded from the policy.")
|
| 780 |
+
q_item = rng.choice(items)
|
| 781 |
+
ans = 1.0 if q_item in covered else 0.0
|
| 782 |
+
qs = [q_noul("covered",
|
| 783 |
+
f"Are {q_item} covered under {person}'s policy?",
|
| 784 |
+
ans)]
|
| 785 |
+
return st, qs
|
| 786 |
+
elif kind < 0.7:
|
| 787 |
+
# unanswerable: missing info
|
| 788 |
+
st = (f"{person} submitted a request on "
|
| 789 |
+
f"{(date(2025, 3, 1) + timedelta(days=rng.randint(0, 300))).strftime('%B %d')}. "
|
| 790 |
+
f"The policy states requests are processed in order of "
|
| 791 |
+
f"submission, subject to officer availability. The "
|
| 792 |
+
f"processing log for this period was lost.")
|
| 793 |
+
opts, ci = _mk_opts(CANNOT,
|
| 794 |
+
["3 days", "7 days", "14 days"], 4)
|
| 795 |
+
qs = [q_choice("when", "How long did processing take?",
|
| 796 |
+
opts, _onehot(4, ci))]
|
| 797 |
+
return st, qs
|
| 798 |
+
else:
|
| 799 |
+
# scope trap: policy applies to a subset only
|
| 800 |
+
grp = rng.choice(["full-time staff", "managers",
|
| 801 |
+
"contractors", "interns"])
|
| 802 |
+
other = rng.choice([g for g in ["full-time staff", "managers",
|
| 803 |
+
"contractors", "interns"]
|
| 804 |
+
if g != grp])
|
| 805 |
+
benefit = rng.choice(["the gym stipend", "remote Fridays",
|
| 806 |
+
"the parking subsidy", "stock options"])
|
| 807 |
+
who_grp = rng.choice([grp, other])
|
| 808 |
+
st = (f"Company handbook: {benefit} is available to {grp} only. "
|
| 809 |
+
f"{person} is a member of {who_grp}.")
|
| 810 |
+
ans = 1.0 if who_grp == grp else 0.0
|
| 811 |
+
qs = [q_noul("eligible",
|
| 812 |
+
f"Is {person} eligible for {benefit}?", ans)]
|
| 813 |
+
return st, qs
|
| 814 |
+
|
| 815 |
+
|
| 816 |
+
# ------------------------------------------------------------------
|
| 817 |
+
# evidence — claim vs evidence set
|
| 818 |
+
# ------------------------------------------------------------------
|
| 819 |
+
|
| 820 |
+
def gen_evidence():
|
| 821 |
+
city = rng.choice(CITIES)
|
| 822 |
+
org = rng.choice(ORGS)
|
| 823 |
+
year = rng.randint(2015, 2024)
|
| 824 |
+
metric = rng.choice(["revenue", "headcount", "fleet size",
|
| 825 |
+
"energy usage"])
|
| 826 |
+
val = rng.randint(2, 98)
|
| 827 |
+
kind = rng.random()
|
| 828 |
+
claim = f"{org} reported {val}% growth in {metric} in {year}."
|
| 829 |
+
if kind < 0.4:
|
| 830 |
+
ev_ok = (f"{org}'s {year} annual report shows a {val}% increase "
|
| 831 |
+
f"in {metric} compared with {year - 1}.")
|
| 832 |
+
verdict = "supported"
|
| 833 |
+
elif kind < 0.7:
|
| 834 |
+
ev_ok = (f"{org}'s {year} annual report shows a "
|
| 835 |
+
f"{max(1, val - 30)}% increase in {metric} compared "
|
| 836 |
+
f"with {year - 1}.")
|
| 837 |
+
verdict = "refuted"
|
| 838 |
+
else:
|
| 839 |
+
ev_ok = (f"{org} relocated its {city} office in {year}.")
|
| 840 |
+
verdict = "neither supported nor refuted"
|
| 841 |
+
ev_near = (f"{org} expanded operations in {city} in {year}, "
|
| 842 |
+
f"opening two new sites.")
|
| 843 |
+
evs = [ev_ok, ev_near]
|
| 844 |
+
rng.shuffle(evs)
|
| 845 |
+
state = (f"Claim: {claim}\nEvidence:\n" +
|
| 846 |
+
"\n".join(f"[{i}] {e}" for i, e in enumerate(evs)))
|
| 847 |
+
verdicts = ["supported", "refuted", "neither supported nor refuted"]
|
| 848 |
+
qs = [q_choice("verdict",
|
| 849 |
+
"Is the claim supported, refuted, or neither, based "
|
| 850 |
+
"only on the evidence?",
|
| 851 |
+
verdicts, _onehot(3, verdicts.index(verdict))),
|
| 852 |
+
q_choice("which",
|
| 853 |
+
"Which evidence item is most relevant to the verdict?",
|
| 854 |
+
evs, _onehot(2, evs.index(ev_ok)))]
|
| 855 |
+
return state, qs
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
# ------------------------------------------------------------------
|
| 859 |
+
# tradeoff — constrained argmax
|
| 860 |
+
# ------------------------------------------------------------------
|
| 861 |
+
|
| 862 |
+
def gen_tradeoff():
|
| 863 |
+
n = rng.choice([4, 5])
|
| 864 |
+
names = rng.sample([f"Plan {c}" for c in "ABCDEF"], n)
|
| 865 |
+
cost = [rng.randint(5, 50) for _ in range(n)]
|
| 866 |
+
qual = [rng.randint(1, 10) for _ in range(n)]
|
| 867 |
+
speed = [rng.randint(1, 10) for _ in range(n)]
|
| 868 |
+
budget = rng.randint(15, 45)
|
| 869 |
+
wq, ws = rng.choice([2, 3]), rng.choice([1, 2])
|
| 870 |
+
feasible = [i for i in range(n) if cost[i] <= budget]
|
| 871 |
+
if not feasible:
|
| 872 |
+
raise ValueError("no feasible plan")
|
| 873 |
+
scores = [wq * qual[i] + ws * speed[i] for i in range(n)]
|
| 874 |
+
best = max(feasible, key=lambda i: scores[i])
|
| 875 |
+
if sum(1 for i in feasible if scores[i] == scores[best]) > 1:
|
| 876 |
+
raise ValueError("tie")
|
| 877 |
+
lines = [f"- {names[i]}: cost {cost[i]}, quality {qual[i]}/10, "
|
| 878 |
+
f"delivery speed {speed[i]}/10" for i in range(n)]
|
| 879 |
+
state = (f"Vendor proposals (budget cap: {budget} cost units):\n" +
|
| 880 |
+
"\n".join(lines))
|
| 881 |
+
instr = (f"Score each feasible plan as {wq}×quality + {ws}×speed; "
|
| 882 |
+
f"plans over budget are infeasible. Pick the highest score.")
|
| 883 |
+
qs = [q_choice("best", instr, names, _onehot(n, best))]
|
| 884 |
+
return state, qs
|
| 885 |
+
|
| 886 |
+
|
| 887 |
+
FAMILIES = {
|
| 888 |
+
"policy_pack": gen_policy_pack,
|
| 889 |
+
"intent_v2": gen_intent_v2,
|
| 890 |
+
"intent_pair": gen_intent_pair,
|
| 891 |
+
"rubric": gen_rubric,
|
| 892 |
+
"routing_v2": gen_routing,
|
| 893 |
+
"multihop": gen_multihop,
|
| 894 |
+
"numeric_chain": gen_numeric_chain,
|
| 895 |
+
"state_track": gen_state_track,
|
| 896 |
+
"temporal_v2": gen_temporal,
|
| 897 |
+
"trap_v2": gen_trap,
|
| 898 |
+
"evidence": gen_evidence,
|
| 899 |
+
"tradeoff": gen_tradeoff,
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
WEIGHTS = {
|
| 903 |
+
"policy_pack": 0.18,
|
| 904 |
+
"intent_v2": 0.14,
|
| 905 |
+
"intent_pair": 0.06,
|
| 906 |
+
"rubric": 0.08,
|
| 907 |
+
"routing_v2": 0.08,
|
| 908 |
+
"multihop": 0.12,
|
| 909 |
+
"numeric_chain": 0.08,
|
| 910 |
+
"state_track": 0.08,
|
| 911 |
+
"temporal_v2": 0.06,
|
| 912 |
+
"trap_v2": 0.06,
|
| 913 |
+
"evidence": 0.03,
|
| 914 |
+
"tradeoff": 0.03,
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
def main(n=60000, seed=0, out="data/jb4.jsonl"):
|
| 919 |
+
rows = generate(FAMILIES, WEIGHTS, n, seed, rng)
|
| 920 |
+
seen, uniq = set(), []
|
| 921 |
+
for r in rows:
|
| 922 |
+
h = hash((r["state"], json.dumps(r["questions"], sort_keys=True)))
|
| 923 |
+
if h in seen:
|
| 924 |
+
continue
|
| 925 |
+
seen.add(h)
|
| 926 |
+
uniq.append(r)
|
| 927 |
+
write_jsonl(uniq, out)
|
| 928 |
+
print(f"wrote {len(uniq)} unique rows -> {out}")
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
if __name__ == "__main__":
|
| 932 |
+
import sys
|
| 933 |
+
n = int(sys.argv[1]) if len(sys.argv) > 1 else 60000
|
| 934 |
+
seed = int(sys.argv[2]) if len(sys.argv) > 2 else 0
|
| 935 |
+
out = sys.argv[3] if len(sys.argv) > 3 else "data/jb4.jsonl"
|
| 936 |
+
main(n, seed, out)
|