From 14e94d4cb800906967ff52154b2dac34ce95a253 Mon Sep 17 00:00:00 2001 From: Weksa Date: Thu, 12 Nov 2026 12:58:09 +0000 Subject: [PATCH] decide_panel rejects a composite fall past its floor; pin cycle floors, ablation, offer, recall and the ja-JP no-text check; drop the redundant tag branch Co-Authored-By: Claude Sonnet 5.5 --- crates/weksa/src/run.rs | 55 +++++++++++-- crates/weksa/tests/golf_loop.rs | 79 +++++++++++++++++++ .../cultnet/weksa.loop_decision.schema.json | 17 +++- 3 files changed, 140 insertions(+), 11 deletions(-) diff --git a/crates/weksa/src/run.rs b/crates/weksa/src/run.rs index f3ae6ee..76c4105 100644 --- a/crates/weksa/src/run.rs +++ b/crates/weksa/src/run.rs @@ -41,7 +41,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::context::{EditFeedback, EncoderOffer, Prompt, TrainItems}; use crate::corpus::{CorpusItem, CorpusItemId, ModelFamily, Source}; use crate::encode::{EditDraft, LoweringDraft, PacketDraft, encoder_id}; -use crate::form::{is_attestation, is_language_tag, is_slug}; +use crate::form::{is_attestation, is_slug}; use crate::model::{ModelPort, PortError}; use crate::packet::{Packet, Stance}; use crate::score::{CHRF_VERSION, chrf, Embedder, ItemScore, ScoreInput, Scorer, SplitMean, aggregate}; @@ -647,10 +647,9 @@ impl RunStores { } let mut panel = panel.to_vec(); panel.sort(); - if panel.is_empty() - || !panel.iter().all(|tag| is_language_tag(tag)) - || panel.windows(2).any(|w| w[0] == w[1]) - { + // A tag no item carries (misspelt, wrong case, not a tag) is refused by + // `check_panel` once the corpus is open. + if panel.is_empty() || panel.windows(2).any(|w| w[0] == w[1]) { return Err(RunError::Panel); } let cache = run_cache(root)?; @@ -1723,6 +1722,8 @@ impl Reading { pub enum Metric { Chrf, Meaning, + /// Only the panel rule reads it: [`decide_panel`]. + Composite, } /// Why an edit was rejected. @@ -1776,7 +1777,11 @@ pub fn decide(base: &Reading, candidate: &Reading, floor: &Reading) -> Verdict { /// The accept rule across the panel, over one `(base, candidate, floor)` row /// per panel language in panel order: [`decide`] per language, unchanged, then /// Pareto non-regression. Any language that regresses rejects (the first in -/// panel order names the metric); otherwise the edit is accepted when at least +/// panel order names the metric); a language regresses when [`decide`] says so +/// or when its composite falls below its base by more than its tolerance, the +/// floor but never under one [`LADDER_STEP`] (compared in billionths, as +/// [`decide`] does), because each metric inside its tolerance can still sum to +/// a composite drop that two opposed accepts would ratchet. Otherwise the edit is accepted when at least /// one language gains past its own threshold, and rejected as no gain when none /// does. A language never buys another's regression: Wang, Lipton and Tsvetkov /// (EMNLP 2020) measure negative interference between languages sharing @@ -1785,7 +1790,17 @@ pub fn decide(base: &Reading, candidate: &Reading, floor: &Reading) -> Verdict { pub fn decide_panel(rows: &[(Reading, Reading, Reading)]) -> Verdict { let verdicts: Vec = rows .iter() - .map(|(base, candidate, floor)| decide(base, candidate, floor)) + .map(|(base, candidate, floor)| { + match decide(base, candidate, floor) { + Verdict::Rejected(Why::NoGain) | Verdict::Accepted + if nano(candidate.composite - base.composite) + < -nano(floor.composite.max(LADDER_STEP)) => + { + Verdict::Rejected(Why::Regressed(Metric::Composite)) + } + verdict => verdict, + } + }) .collect(); if let Some(regressed) = verdicts .iter() @@ -1921,6 +1936,7 @@ impl Decision { Why::NoGain => "no-gain", Why::Regressed(Metric::Chrf) => "regressed-chrf", Why::Regressed(Metric::Meaning) => "regressed-meaning", + Why::Regressed(Metric::Composite) => "regressed-composite", } ), }; @@ -2377,6 +2393,31 @@ mod tests { decide_panel(&[(base, reading(60.0, 0.9, 0.9), zero), (base, tiny_loss, zero)]), rejected(Why::Regressed(Metric::Chrf)) ); + // Metrics each inside their tolerance, the composite past its own: + // another language's gain cannot buy it. + let sag = reading(49.6, 0.496, 0.4); + let tol = reading(0.5, 0.005, 0.05); + assert_eq!(decide(&base, &sag, &tol), rejected(Why::NoGain)); + assert_eq!( + decide_panel(&[(base, gained, zero), (base, sag, tol)]), + rejected(Why::Regressed(Metric::Composite)) + ); + assert_eq!( + decide_panel(&[(base, sag, tol), (base, gained, zero)]), + rejected(Why::Regressed(Metric::Composite)) + ); + // Two edits that undo each other cannot both be accepted: the second + // undoes the first's gain by the first's loss, and one language falls. + let (a0, a1) = (reading(50.0, 0.5, 0.50), reading(50.0, 0.5, 0.60)); + let (b0, b1) = (reading(50.0, 0.5, 0.50), reading(50.0, 0.5, 0.40)); + assert_eq!(decide_panel(&[(a0, a1, zero), (b0, b1, zero)]), rejected(Why::Regressed(Metric::Composite))); + assert_eq!(decide_panel(&[(a1, a0, zero), (b1, b0, zero)]), rejected(Why::Regressed(Metric::Composite))); + // A fall inside the floor (and each metric inside its own) still accepts. + let wide = reading(50.0, 0.5, 0.05); + assert_eq!( + decide_panel(&[(base, gained, zero), (base, reading(49.6, 0.496, 0.47), wide)]), + Verdict::Accepted + ); // A one-language panel is decide(). for candidate in [gained, regressed, flat, meaning_down] { assert_eq!( diff --git a/crates/weksa/tests/golf_loop.rs b/crates/weksa/tests/golf_loop.rs index 869482b..73f1df2 100644 --- a/crates/weksa/tests/golf_loop.rs +++ b/crates/weksa/tests/golf_loop.rs @@ -4259,6 +4259,15 @@ fn each_item_lowers_in_its_own_language() { } } assert_eq!((ja, en), (3, 3)); + // No lowering prompt, in either language, holds any item's text, key or group. + let corpus = CorpusStore::open(&dao.corpus).unwrap(); + for text in lowering_texts(&model) { + for item in corpus.all().unwrap() { + assert!(!text.contains(&item.text), "{}", item.id); + assert!(!text.contains(item.id.as_str()), "{}", item.id); + assert!(!text.contains(item.group.as_str()), "{}", item.id); + } + } // A ja-JP item is scored against its own text: the lowering that is the // text reads as a perfect one. let ja = r.language("ja-JP").unwrap(); @@ -4461,8 +4470,17 @@ fn recall_probes_unspaced_lines() { let (head, tail) = (shown_opening(prompt), held_back(&item.text, prompt)); assert!(!head.is_empty() && !tail.is_empty()); assert_eq!(format!("{head}{tail}"), item.text, "no spaces to lose"); + let n = item.text.len(); + assert!((n / 4..=3 * n / 4).contains(&head.len()), "{key}: near the byte middle"); assert!(!prompt.contains(tail)); } + // The unrelated-text floor was measured for English only: its clause + // prints once, on the en-US segment. + let line = reading.line(); + assert_eq!(line.matches("unrelated English").count(), 1, "{line}"); + let (first, second) = line.split_once(" | ").unwrap(); + assert!(first.starts_with("recall en-US") && first.contains("unrelated English"), "{line}"); + assert!(second.starts_with("recall ja-JP") && !second.contains("unrelated"), "{line}"); // en-US still splits between words. let en = reading.languages.iter().find(|l| l.language == "en-US").unwrap(); assert_eq!((en.n, en.answered), (3, 3)); @@ -4478,3 +4496,64 @@ fn recall_probes_unspaced_lines() { assert!(!next.is_alphanumeric(), "{key}: cut inside a word"); } } + +#[test] +fn offer_by_key_is_the_panels_too() { + let dao = bilingual(LAOZI_JA); + assert!(dao.run.offer("item:daodejing:12").unwrap().is_ok(), "ja-JP is in the panel"); + assert!(dao.run.offer("item:daodejing:2").unwrap().is_ok()); + for pt in ["item:daodejing:21", "item:daodejing:22", "item:daodejing:23"] { + assert!(dao.run.offer(pt).is_err(), "{pt}: pt-BR is outside the panel"); + } +} + +#[test] +fn a_cycle_decides_each_language_on_its_own_floor() { + let mut dao = bilingual(LAOZI_JA); + // en-US reads the same twice (floor 0); ja-JP loses a Validation item in + // round 2 (a wide floor). + let mut first = bilingual_fake(); + recorded(round(&mut dao.run, &mut first, &Scorer::new(Bag)).unwrap()); + let mut second = bilingual_fake(); + second.answers.insert("item:daodejing:13".into(), "not a draft".into()); + recorded(round(&mut dao.run, &mut second, &Scorer::new(Bag)).unwrap()); + // The candidate degrades en-US a little and leaves ja-JP as it was. + let mut model = bilingual_fake(); + model.candidate = Some((4, { + let mut candidate = bilingual_answers(); + candidate.extend(keyed(°raded_answers())); + candidate + })); + model.edit = Some(Ok(ONE_CONCEPT.to_string())); + let d = run_cycle(&mut dao, &mut model); + let (en, ja) = (&d.panel()[0], &d.panel()[1]); + assert_eq!((en.language.as_str(), ja.language.as_str()), ("en-US", "ja-JP")); + assert_eq!(en.floor.chrf, 0.0); + assert_eq!(ja.floor.chrf, 50.0); + // en-US fell by more than its own floor but by less than ja-JP's: the + // verdict is the rejection that en-US's floor makes, not NoGain. + let fall = en.base.chrf - en.candidate.unwrap().chrf; + assert!(fall > 1.0 && fall < ja.floor.chrf, "{fall}"); + assert!(matches!(d.verdict(), Verdict::Rejected(Why::Regressed(_))), "{:?}", d.verdict()); +} + +#[test] +fn ablation_reads_each_language_apart() { + let mut dao = bilingual(LAOZI_JA); + let mut model = bilingual_fake(); + recorded(round(&mut dao.run, &mut model, &Scorer::new(Bag)).unwrap()); + let (mut rec, mut replay) = (bilingual_fake(), bilingual_fake()); + let readings = match ablate(&dao, &mut rec, &mut replay).unwrap() { + weksa::run::AblationOutcome::Read(r) => r, + _ => panic!("answered"), + }; + let shape: Vec<(&str, weksa::Split, u32)> = readings + .iter() + .map(|(l, split, r)| (l.as_str(), *split, r.n)) + .collect(); + use weksa::Split::{Train, Validation}; + assert_eq!( + shape, + [("en-US", Train, 1), ("en-US", Validation, 2), ("ja-JP", Train, 1), ("ja-JP", Validation, 2)] + ); +} diff --git a/schemas/cultnet/weksa.loop_decision.schema.json b/schemas/cultnet/weksa.loop_decision.schema.json index 4d4bfbe..9838e3a 100644 --- a/schemas/cultnet/weksa.loop_decision.schema.json +++ b/schemas/cultnet/weksa.loop_decision.schema.json @@ -98,10 +98,19 @@ }, "Metric": { "description": "Which metric an edit regressed.", - "type": "string", - "enum": [ - "Chrf", - "Meaning" + "oneOf": [ + { + "type": "string", + "enum": [ + "Chrf", + "Meaning" + ] + }, + { + "description": "Only the panel rule reads it: [`decide_panel`].", + "type": "string", + "const": "Composite" + } ] }, "PanelReading": {