v0.5: evidence-aligned windows + 42% EN rebalance + dual-language canaries; canary-aware trainer
This commit is contained in:
parent
4b80e5de46
commit
384c657525
@ -139,6 +139,15 @@ def main():
|
||||
dl = DataLoader(PairDS(train, tok), batch_size=args.bs, shuffle=True, num_workers=2, drop_last=True)
|
||||
dl_cal = DataLoader(PairDS(calib, tok), batch_size=64, num_workers=2)
|
||||
|
||||
# 金丝雀: 双语言切片逐 epoch 评估, best 按 min(auc_en, auc_zh) 选择(防单语言偏科)
|
||||
canaries = {}
|
||||
for lang in ["en", "zh"]:
|
||||
p = os.path.join(args.data, f"canary_{lang}.jsonl")
|
||||
if os.path.exists(p):
|
||||
dl_c = DataLoader(PairDS(load_jsonl(p), tok), batch_size=64, num_workers=2)
|
||||
canaries[lang] = dl_c
|
||||
print(f"[jev] canaries: {list(canaries) or '无(单语言模式)'}", flush=True)
|
||||
|
||||
steps = len(dl) * args.epochs
|
||||
opt = torch.optim.AdamW(model.parameters(), lr=args.lr, weight_decay=0.01)
|
||||
sch = get_cosine_schedule_with_warmup(opt, int(0.06 * steps), steps)
|
||||
@ -163,7 +172,12 @@ def main():
|
||||
print(f"[jev] ep{ep} step{gstep}/{steps} loss={loss.item():.4f}", flush=True)
|
||||
m = evaluate(model, dl_cal, dev)
|
||||
print(f"[jev] epoch {ep} calibration: {m}", flush=True)
|
||||
if m["auc"] > best["auc"]:
|
||||
sel_score = m["auc"]
|
||||
for lang, dl_c in canaries.items():
|
||||
cm = evaluate(model, dl_c, dev)
|
||||
print(f"[jev] epoch {ep} canary_{lang}: {cm}", flush=True)
|
||||
sel_score = min(sel_score, cm["auc"]) # 最差语言决定选择
|
||||
if sel_score > best["auc"]:
|
||||
best = {"auc": m["auc"], "ece": m["ece"], "epoch": ep}
|
||||
model.save_pretrained(os.path.join(args.out, "model"))
|
||||
tok.save_pretrained(os.path.join(args.out, "model"))
|
||||
|
||||
BIN
v05/jev_part_00
Normal file
BIN
v05/jev_part_00
Normal file
Binary file not shown.
BIN
v05/jev_part_01
Normal file
BIN
v05/jev_part_01
Normal file
Binary file not shown.
BIN
v05/jev_part_02
Normal file
BIN
v05/jev_part_02
Normal file
Binary file not shown.
BIN
v05/jev_part_03
Normal file
BIN
v05/jev_part_03
Normal file
Binary file not shown.
BIN
v05/jev_part_04
Normal file
BIN
v05/jev_part_04
Normal file
Binary file not shown.
BIN
v05/jev_part_05
Normal file
BIN
v05/jev_part_05
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user