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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 9 |
+
sys.path.insert(0, str(ROOT))
|
| 10 |
+
|
| 11 |
+
from training.generate_jawbreaker_data import ( # noqa: E402
|
| 12 |
+
eval_row,
|
| 13 |
+
generated_cases,
|
| 14 |
+
sft_row,
|
| 15 |
+
write_jsonl,
|
| 16 |
+
)
|
| 17 |
+
from training.generate_v2_data import hard_cases, hard_prediction # noqa: E402
|
| 18 |
+
from training.generate_v3_data import boundary_cases, split_special_cases # noqa: E402
|
| 19 |
+
from training.generate_v4_data import v4_cases # noqa: E402
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
CALIBRATION_CASES = [
|
| 23 |
+
{
|
| 24 |
+
"category": "official_route_calibration_v5",
|
| 25 |
+
"risk": "needs_check",
|
| 26 |
+
"scam_type": "possible_legitimate_alert",
|
| 27 |
+
"tactics": ["verification needed", "trusted route"],
|
| 28 |
+
"impersonates": "service provider",
|
| 29 |
+
"pressure": "routine safety or account notice",
|
| 30 |
+
"ask": "verify through official app, official website, or known route",
|
| 31 |
+
"risk_text": "uncertain legitimacy",
|
| 32 |
+
"safe_action": "Verify directly through the official app, official website, or a known phone number.",
|
| 33 |
+
"messages": [
|
| 34 |
+
"Bank notice: a new device signed in. If this was not you, open the official banking app and review security.",
|
| 35 |
+
"Credit union alert: profile contact info changed. Use the mobile app or call the number on your card to review.",
|
| 36 |
+
"Card alert: did you attempt a $44.18 grocery purchase? Reply YES or NO, or call the number on your card.",
|
| 37 |
+
"Coinbase notice: your password was changed. Open the official app yourself to review account security.",
|
| 38 |
+
"PayPal security: a new passkey was added. Go through the app or paypal.com directly if this was not you.",
|
| 39 |
+
"Utility account: your statement is ready. Pay only through your normal account or the number printed on your bill.",
|
| 40 |
+
"Phone carrier: SIM protection was updated. Open the carrier app directly to check your account.",
|
| 41 |
+
"County office: your property notice is ready. Visit the official county website from prior mail.",
|
| 42 |
+
"Airline alert: your flight changed. Open the airline app directly to confirm the new time.",
|
| 43 |
+
"Insurance notice: explanation of benefits is ready. Review it through your normal member portal.",
|
| 44 |
+
"School portal: report cards are available. Sign in through the normal parent portal.",
|
| 45 |
+
"Delivery update: your package is out for delivery. Track it in the official carrier app.",
|
| 46 |
+
"Pharmacy: prescription refill is ready. Use your normal pharmacy account or store phone number for details.",
|
| 47 |
+
"Hospital portal: new lab results are available. Sign in through your usual patient portal.",
|
| 48 |
+
"Streaming service: payment method needs attention. Open the official app or website yourself.",
|
| 49 |
+
"Library notice: a requested item is ready. Log in through the normal library site if you need details.",
|
| 50 |
+
],
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"category": "legitimate_notice_calibration_v5",
|
| 54 |
+
"risk": "needs_check",
|
| 55 |
+
"scam_type": "possible_legitimate_alert",
|
| 56 |
+
"tactics": ["verification needed", "trusted route"],
|
| 57 |
+
"impersonates": "known service",
|
| 58 |
+
"pressure": "low-pressure routine notice",
|
| 59 |
+
"ask": "check the normal account or known contact path",
|
| 60 |
+
"risk_text": "uncertain legitimacy",
|
| 61 |
+
"safe_action": "Verify directly through the official app, official website, or a known phone number.",
|
| 62 |
+
"messages": [
|
| 63 |
+
"Your dentist appointment is confirmed for Tuesday at 2 PM. Reply C to confirm or call the office number you already have.",
|
| 64 |
+
"Clinic reminder: please review your pre-visit forms in the patient portal before tomorrow.",
|
| 65 |
+
"Auto shop update: your car is ready for pickup. Call our main shop number if you have questions.",
|
| 66 |
+
"Apartment office: package pickup hours changed today. Check the resident portal for details.",
|
| 67 |
+
"Library account: one item is due soon. Renew through the library website or front desk.",
|
| 68 |
+
"School reminder: permission forms are due Friday. Check the parent portal for details.",
|
| 69 |
+
"Transit card notice: your monthly pass renews tomorrow. Review it in your normal transit account.",
|
| 70 |
+
"Gym notice: holiday hours changed. Open the member app if you want the schedule.",
|
| 71 |
+
"Tax software: your draft return is ready for review. Sign in through the app you already use.",
|
| 72 |
+
"Vet clinic: vaccine records are available in your pet portal.",
|
| 73 |
+
"Bank statement ready: open your official banking app or website to view it.",
|
| 74 |
+
"Pharmacy order shipped: track it through your normal pharmacy account.",
|
| 75 |
+
],
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"category": "benign_scary_calibration_v5",
|
| 79 |
+
"risk": "safe",
|
| 80 |
+
"scam_type": "none",
|
| 81 |
+
"tactics": [],
|
| 82 |
+
"impersonates": "known sender",
|
| 83 |
+
"pressure": "no sensitive pressure",
|
| 84 |
+
"ask": "no sensitive ask",
|
| 85 |
+
"risk_text": "none identified",
|
| 86 |
+
"safe_action": "If this came from someone you know and asks for nothing sensitive, it is probably safe. Still avoid unexpected links.",
|
| 87 |
+
"messages": [
|
| 88 |
+
"School alert: the lockdown drill is complete. Students are safe and classes have resumed.",
|
| 89 |
+
"Clinic notice: lab results are available in the portal. No urgent action is required.",
|
| 90 |
+
"Building notice: fire alarm testing starts at 3 PM. No evacuation is needed.",
|
| 91 |
+
"Weather alert from school: after-school practice is cancelled. Pickup is at the usual door.",
|
| 92 |
+
"Library reminder: your book hold expires Friday. No payment is due.",
|
| 93 |
+
"Dentist reminder: appointment tomorrow morning. Call the office number on your calendar if needed.",
|
| 94 |
+
"Office notice: security badges will be checked at the front desk tomorrow.",
|
| 95 |
+
"Neighborhood update: roadwork begins Monday. Use the signed detour.",
|
| 96 |
+
"Pharmacy reminder: refill is ready at your usual store.",
|
| 97 |
+
"Court reminder: jury check-in starts Monday. Bring the summons you received in the mail.",
|
| 98 |
+
"HR reminder: benefits enrollment closes Friday. Use the company portal.",
|
| 99 |
+
"Utility notice: meter reading is scheduled this week. No appointment is required.",
|
| 100 |
+
],
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"category": "marketplace_calibration_v5",
|
| 104 |
+
"risk": "suspicious",
|
| 105 |
+
"scam_type": "marketplace_scam",
|
| 106 |
+
"tactics": ["marketplace", "third party", "payment pressure"],
|
| 107 |
+
"impersonates": "buyer or seller",
|
| 108 |
+
"pressure": "unusual marketplace flow",
|
| 109 |
+
"ask": "leave the marketplace, share codes, or handle third-party payment",
|
| 110 |
+
"risk_text": "overpayment or account theft",
|
| 111 |
+
"safe_action": "Pause before acting. Keep payment and messages inside the marketplace's official flow.",
|
| 112 |
+
"messages": [
|
| 113 |
+
"I can buy the couch today, but my cousin will pick it up and I will send extra money.",
|
| 114 |
+
"The courier asks for a small insurance deposit. Pay it now and I will add it to your total.",
|
| 115 |
+
"I sent a code to prove you are real. Send it back before I pay.",
|
| 116 |
+
"My assistant pays by company email. Send your bank name so accounting can release funds.",
|
| 117 |
+
"Please mark the item sold and move to text because my marketplace account is limited.",
|
| 118 |
+
"Use this escrow page for the payment before pickup.",
|
| 119 |
+
"I accidentally overpaid and need you to refund the difference to my driver.",
|
| 120 |
+
"I am ready to buy but need your email to send a marketplace verification link.",
|
| 121 |
+
"Can you hold the item if I send a check and arrange movers later?",
|
| 122 |
+
"The buyer protection page says you need to pay a refundable seller fee.",
|
| 123 |
+
"I am out of town, but I can send a courier if you pay their pickup fee first.",
|
| 124 |
+
"Please verify the sale by reading me the account code you just received.",
|
| 125 |
+
],
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"category": "suspicious_urgency_calibration_v5",
|
| 129 |
+
"risk": "suspicious",
|
| 130 |
+
"scam_type": "unknown_urgent_request",
|
| 131 |
+
"tactics": ["urgency", "vague request"],
|
| 132 |
+
"impersonates": "unknown sender",
|
| 133 |
+
"pressure": "act quickly without enough context",
|
| 134 |
+
"ask": "respond, confirm, or review unclear issue",
|
| 135 |
+
"risk_text": "uncertain legitimacy",
|
| 136 |
+
"safe_action": "Pause before responding. Verify through an official app, website, or known phone number.",
|
| 137 |
+
"messages": [
|
| 138 |
+
"Please call me back immediately about your account. This cannot wait.",
|
| 139 |
+
"Final reminder: your paperwork is missing. Send your details by end of day.",
|
| 140 |
+
"Action required: confirm ownership within 24 hours.",
|
| 141 |
+
"We noticed an issue with your delivery. Respond quickly so we can resolve it.",
|
| 142 |
+
"Your subscription has a problem. We need confirmation today or it may close.",
|
| 143 |
+
"Urgent account message: please review the notice as soon as possible.",
|
| 144 |
+
"We need a response before 5 PM to avoid delays.",
|
| 145 |
+
"Your request cannot be completed until you confirm a few details.",
|
| 146 |
+
"Important: your file is on hold. Reply when available.",
|
| 147 |
+
"Your account review is pending. A response is needed today.",
|
| 148 |
+
],
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"category": "dangerous_contrast_calibration_v5",
|
| 152 |
+
"risk": "dangerous",
|
| 153 |
+
"scam_type": "credential_theft",
|
| 154 |
+
"tactics": ["fake authority", "credential request", "suspicious link", "urgency"],
|
| 155 |
+
"impersonates": "service provider",
|
| 156 |
+
"pressure": "account, payment, or delivery emergency",
|
| 157 |
+
"ask": "use a message link, message number, code, card, or login",
|
| 158 |
+
"risk_text": "credential or payment theft",
|
| 159 |
+
"safe_action": "Do not use links or phone numbers from the message. Open the official app or website yourself.",
|
| 160 |
+
"messages": [
|
| 161 |
+
"Bank alert: new device signed in. Verify your password at http://bank-security-review.example within 10 minutes.",
|
| 162 |
+
"Credit union: card locked. Call the number in this text and read your one-time code to cancel fraud.",
|
| 163 |
+
"Delivery center: package held for a $2.19 fee. Enter address and card at http://parcel-release-fee.example.",
|
| 164 |
+
"PayPal warning: passkey added. Secure your account at https://paypal-case-review.example and enter the code.",
|
| 165 |
+
"Hospital billing: results blocked until you upload ID and insurance number at this link.",
|
| 166 |
+
"Utility shutoff: pay through this urgent portal today or service will end.",
|
| 167 |
+
"County tax final notice: pay the penalty fee through the link below before noon.",
|
| 168 |
+
"Airline refund desk: provide card details at this refund link to keep your ticket.",
|
| 169 |
+
"School portal emergency form missing. Enter parent login and payment card at this link.",
|
| 170 |
+
"Streaming billing: payment failed and your account closes tonight. Update at http://streaming-billing-review.example.",
|
| 171 |
+
"Card fraud center: suspicious grocery purchase. Call this alert number and verify your full card number.",
|
| 172 |
+
"Coinbase security: phone update requested. Contact support at the callback number in this text.",
|
| 173 |
+
],
|
| 174 |
+
},
|
| 175 |
+
]
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def calibration_cases(repeats: int) -> list[tuple[str, dict, dict]]:
|
| 179 |
+
cases = []
|
| 180 |
+
for repeat in range(repeats):
|
| 181 |
+
for case in CALIBRATION_CASES:
|
| 182 |
+
prediction = hard_prediction(case)
|
| 183 |
+
for index, message in enumerate(case["messages"]):
|
| 184 |
+
case_id = f"{case['category']}_{repeat:02d}_{index:02d}"
|
| 185 |
+
cases.append((case_id, {"message": message, "scenario": case}, prediction))
|
| 186 |
+
return cases
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def parse_args() -> argparse.Namespace:
|
| 190 |
+
parser = argparse.ArgumentParser(description="Generate Jawbreaker v5 1B calibration data.")
|
| 191 |
+
parser.add_argument("--base-train", type=int, default=680)
|
| 192 |
+
parser.add_argument("--base-dev", type=int, default=120)
|
| 193 |
+
parser.add_argument("--base-test", type=int, default=180)
|
| 194 |
+
parser.add_argument("--hard-repeats", type=int, default=4)
|
| 195 |
+
parser.add_argument("--boundary-repeats", type=int, default=5)
|
| 196 |
+
parser.add_argument("--v4-repeats", type=int, default=5)
|
| 197 |
+
parser.add_argument("--calibration-repeats", type=int, default=5)
|
| 198 |
+
parser.add_argument("--out-dir", type=Path, default=ROOT / "training" / "data")
|
| 199 |
+
parser.add_argument("--eval-out", type=Path, default=ROOT / "eval" / "hard_v5_eval.jsonl")
|
| 200 |
+
return parser.parse_args()
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def main() -> None:
|
| 204 |
+
args = parse_args()
|
| 205 |
+
total = args.base_train + args.base_dev + args.base_test
|
| 206 |
+
base = list(generated_cases(total))
|
| 207 |
+
v2_hard = hard_cases(args.hard_repeats)
|
| 208 |
+
boundary = boundary_cases(args.boundary_repeats)
|
| 209 |
+
v4 = v4_cases(args.v4_repeats)
|
| 210 |
+
calibration = calibration_cases(args.calibration_repeats)
|
| 211 |
+
|
| 212 |
+
v2_hard_train, v2_hard_dev = split_special_cases(v2_hard, dev_fraction=0.20)
|
| 213 |
+
boundary_train, boundary_dev = split_special_cases(boundary, dev_fraction=0.20)
|
| 214 |
+
v4_train, v4_dev = split_special_cases(v4, dev_fraction=0.20)
|
| 215 |
+
calibration_train, calibration_dev = split_special_cases(calibration, dev_fraction=0.20)
|
| 216 |
+
|
| 217 |
+
train_cases = base[: args.base_train] + v2_hard_train + boundary_train + v4_train + calibration_train
|
| 218 |
+
dev_cases = (
|
| 219 |
+
base[args.base_train : args.base_train + args.base_dev]
|
| 220 |
+
+ v2_hard_dev
|
| 221 |
+
+ boundary_dev
|
| 222 |
+
+ v4_dev
|
| 223 |
+
+ calibration_dev
|
| 224 |
+
)
|
| 225 |
+
test_cases = (
|
| 226 |
+
base[args.base_train + args.base_dev :]
|
| 227 |
+
+ v2_hard_dev
|
| 228 |
+
+ boundary_dev
|
| 229 |
+
+ v4_dev
|
| 230 |
+
+ calibration_dev
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
write_jsonl(args.out_dir / "train_v5.jsonl", (sft_row(*case) for case in train_cases))
|
| 234 |
+
write_jsonl(args.out_dir / "dev_v5.jsonl", (sft_row(*case) for case in dev_cases))
|
| 235 |
+
write_jsonl(args.out_dir / "test_v5.jsonl", (sft_row(*case) for case in test_cases))
|
| 236 |
+
write_jsonl(args.eval_out, (eval_row(*case) for case in test_cases))
|
| 237 |
+
|
| 238 |
+
print(f"wrote train_v5={len(train_cases)} dev_v5={len(dev_cases)} test_v5={len(test_cases)}")
|
| 239 |
+
print(f"v2_hard={len(v2_hard)} boundary={len(boundary)} v4={len(v4)} calibration={len(calibration)}")
|
| 240 |
+
print(f"calibration_train={len(calibration_train)} calibration_dev={len(calibration_dev)}")
|
| 241 |
+
print(f"training data: {args.out_dir}")
|
| 242 |
+
print(f"hard eval: {args.eval_out}")
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
if __name__ == "__main__":
|
| 246 |
+
main()
|