Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ be compared only when no such change lies between them.

### Changed

- **The label-checked boundary F1 judges each boundary against its partner,
and the boundary F1 of every row moves.** `wbnd_f1_all_20ms` and
`bnd_f1_all_20ms` used to pair the boundaries that passed the label check by
time alone, closest first. That lost a hit when a short unit met a steady
lag, and it credited a boundary against one of another name (issue #36). A
reference boundary now counts only against the system boundary between the
same two units, and an error of exactly 20 ms counts as a hit. A row can
move either way. `scoring.boundary_pairing: time` restores the old rule, and
`tests/repro` pins it to rebuild the October 2026 snapshot. The word
timestamp F1, which ranks the word board, does not move.
- **BFA moves from 1.1.5 to 2.1.0, and its rows move with it.** 2.0.0
replaced BFA's acoustic models and decoder, so these are new measurements,
not a rescore. The `bfa` row runs CUPE-3-en, BFA's English model. A recipe
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,15 @@ label-checked boundary F1. The October 2026 snapshot was published before
`n_boundaries` count the boundaries each average covers.
- **F1 at 20 ms, labels checked** (`wbnd_f1_all_20ms`, `bnd_f1_all_20ms`). A
boundary is a hit only when the units on **both** sides of it match the
reference and it lies within 20 ms. The two utterance edges count, against
silence. Every reference boundary is in the denominator, including those of
an utterance a system returned nothing for, so skipping hard material costs
recall. The `n_*_gold_all` and `n_*_hyp_all` columns hold the two
denominators.
reference and its partner lies within 20 ms. The partner is the system
boundary between the same two units in the label alignment, so a boundary of
another name never answers for it, however close. The two utterance edges
count, against silence. Every reference boundary is in the denominator,
including those of an utterance a system returned nothing for, so skipping
hard material costs recall. The `n_*_gold_all` and `n_*_hyp_all` columns
hold the two denominators. This F1 scores one shared point per boundary,
since TIMIT and Buckeye label continuous speech. A real pause, and a word
whose neighbour was misread, are the cases the word timestamp F1 covers.
- **WER and PER** add up the units a system relabelled, dropped or invented,
over the number of reference units. A system that skips hard units to
flatter its MAE pays for them here.
Expand Down
7 changes: 7 additions & 0 deletions fabench/score/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ manner_match: true
# label in either mechanism. Retained here, off by default, as a documented
# "what our best independent guess got vs. the real mechanism" comparison.
exclude_silence_boundaries: false

# How the label-checked boundary F1 pairs a reference boundary with a system
# one. "partner" judges it against its partner alone, the system boundary
# between the same two units in the label alignment, with the TA_TOL_S float
# guard. "time" pairs the gated times closest first with no guard, the rule of
# every snapshot up to October 2026, kept so those can be rebuilt.
boundary_pairing: partner
6 changes: 4 additions & 2 deletions fabench/score/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def score_pair(
matcher: str = "levenshtein",
matcher_lambda: float = 2.0,
exclude_silence_boundaries: bool = False,
boundary_pairing: str = "partner",
boundary_unit: str = "phone",
input_tokens: list[str] | None = None,
extras: Sequence[Callable[[UttScore, SimpleNamespace], None]] = (),
Expand Down Expand Up @@ -308,7 +309,8 @@ def manner_fn(raw_gold_label: str) -> str:
_cgw, _chw, _c_wmatched, gold_ivs, hyp_ivs,
gold_matched=_c_gold_matched,
gold_unit_matched={gi for gi, _ in matched},
hyp_unit_matched={hj for _, hj in matched})
hyp_unit_matched={hj for _, hj in matched},
unit_pairs=matched, pairing=boundary_pairing)
phone = SimpleNamespace(gold_ivs=gold_ivs, hyp_ivs=hyp_ivs, aln=aln,
matched=matched, bmatched=bmatched, manner_fn=manner_fn)

Expand All @@ -329,7 +331,7 @@ def manner_fn(raw_gold_label: str) -> str:
if _gwl:
us.wbnd_all = _wseg.f1_all(
_gwl, _hwl, _waln.matched(_gll, _hll),
gold_matched=_c_gold_matched)
gold_matched=_c_gold_matched, pairing=boundary_pairing)
from fabench.score.matched import edit_counts

# Silence pseudo-words are NOT recognition units. Charsiu and MAPS emit
Expand Down
3 changes: 3 additions & 0 deletions fabench/score/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def score_utts(cfg, extras=()):
matcher = str(scoring.get("matcher", "levenshtein"))
matcher_lambda = float(scoring.get("matcher_lambda", 2.0))
exclude_silence = bool(scoring.get("exclude_silence_boundaries", False))
boundary_pairing = str(scoring.get("boundary_pairing", "partner"))
boundary_unit = str(scoring.get("boundary_unit", "phone")) # phone | word
uttscores = []
from fabench.paths import hyp_path as _hyp_path
Expand Down Expand Up @@ -178,6 +179,7 @@ def _tokens(utt_id, gold):
matcher=matcher,
matcher_lambda=matcher_lambda,
exclude_silence_boundaries=exclude_silence,
boundary_pairing=boundary_pairing,
boundary_unit=boundary_unit,
extras=extras,
context={"record": rec, "n_gold_utts": len(gold_by_id)},
Expand Down Expand Up @@ -213,6 +215,7 @@ def _tokens(utt_id, gold):
matcher=matcher,
matcher_lambda=matcher_lambda,
exclude_silence_boundaries=exclude_silence,
boundary_pairing=boundary_pairing,
boundary_unit=boundary_unit,
extras=extras,
context={"record": {}, "n_gold_utts": len(gold_by_id)},
Expand Down
83 changes: 72 additions & 11 deletions fabench/score/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,33 @@
an inserted one costs precision.

A HIT NEEDS BOTH. A boundary scores only when the units on both sides of it
are matched by label, silence matching silence at an edge, and when a system
boundary of the same kind lies within 20 ms. So a boundary placed at the right
moment beside the wrong word is a miss.
are matched by label, silence matching silence at an edge, and when its
partner lies within 20 ms. So a boundary placed at the right moment beside the
wrong word is a miss.

ITS PARTNER, NOT THE NEAREST TIME. The label alignment pairs each unit with
one unit on the other side, so it also names each boundary's partner, the
system boundary between the same two units. A reference boundary is judged
against that partner alone. A system boundary of another name never answers
for it, however close in time.

STRICT MATCHING. One hypothesis boundary may satisfy at most one reference
boundary and vice versa. Strgar & Harwath (SLT 2022, arXiv:2211.01461) showed
the lenient alternative -- letting one predicted boundary count against several
references inside the tolerance -- moves reported precision by 3-4 points
supervised and 5-7 unsupervised, so the scheme must be stated with any number.
We implement STRICT, matched greedily in order of increasing distance, which is
optimal for the 1-D monotone case here.
We implement STRICT through the partners, which are one to one by
construction. Before this rule the gated times were paired closest first, which
can lose a hit and can credit a boundary of another name (issue #36).
``pairing="time"`` keeps that rule, so the October 2026 snapshot can be rebuilt.
"""
from __future__ import annotations

from collections.abc import Sequence
from dataclasses import dataclass

from fabench.score.boundary import TA_TOL_S

#: The F1 tolerance. 20 ms is what the segmentation literature reports (UnsupSeg,
#: SegFeat, SCPC) and what the paper's tables print.
F1_TOL_S = 0.020
Expand Down Expand Up @@ -67,6 +77,10 @@ def hits_by_tol_pairs(
one, exactly what a run at that narrower tolerance would choose. The pairs
it adds beyond that width come later and cannot displace them. So one run
at the widest width answers every width.

Closest first is not always the most pairs. Reference 0 and 25 ms against
system 15 and 40 ms gives one hit where two exist (issue #36). It is the
rule of ``f1_all(pairing="time")`` only, kept to rebuild October 2026.
"""
if not tols_s:
return {}
Expand Down Expand Up @@ -163,16 +177,21 @@ def _ctx_times(units, fl):
def f1_all(
gold_words, hyp_words, matched_word_pairs, gold_units=None, hyp_units=None,
gold_matched=None, gold_unit_matched=None, hyp_unit_matched=None,
tol_s=F1_TOL_S,
tol_s=F1_TOL_S, unit_pairs=None, pairing="partner",
) -> dict:
"""The label-checked F1 counts of one utterance, ``{"n_gold", "n_hyp", "hits"}``.

Every boundary of the utterance is in a denominator, the edges included,
and only a boundary in `BOTH` can score, so a boundary missed for
misreading the units around it is charged exactly like one put in the
wrong place. Hits pair the reference and system boundaries of `BOTH`
one-to-one within ``tol_s``, closest first. The F1 is
``2 * hits / (n_gold + n_hyp)``.
wrong place. A reference boundary of `BOTH` is a hit when its partner,
the system boundary between the same two units, is in `BOTH` too and lies
within ``tol_s`` (`_partner_hits`). The F1 is ``2 * hits / (n_gold + n_hyp)``.

The partners come from ``matched_word_pairs`` on the word tier and from
``unit_pairs`` on the phone tier. Without ``unit_pairs`` the phone tier has
no partners, and it pairs the gated times closest first, as
``pairing="time"`` does on both tiers.

The recognized words are aligned to the reference words, and a word is
matched when it is label-matched to an aligned word on the other side.
Expand Down Expand Up @@ -200,6 +219,48 @@ def f1_all(
def times(b, keep):
return sorted({round(t, 6) for c, t in b if c in keep})

ms = round(tol_s * 1000)
pairs = matched_word_pairs if gold_units is None else unit_pairs
if pairing == "time" or pairs is None:
hits = hits_by_tol_pairs(times(gb, BOTH), times(hb, BOTH), (tol_s,))[round(tol_s * 1000)]
elif pairing == "partner":
hits = _partner_hits(gu, gf, hu, hf, pairs, tol_s)
else:
raise ValueError(f"pairing must be partner or time, got {pairing!r}")
return {"n_gold": len(times(gb, CTX_CLASSES)), "n_hyp": len(times(hb, CTX_CLASSES)),
"hits": hits_by_tol_pairs(times(gb, BOTH), times(hb, BOTH), (tol_s,))[ms]}
"hits": hits}


def _partner_hits(gu, gf, hu, hf, pairs, tol_s) -> int:
"""Hits when each reference boundary is judged against its partner alone.

An interior boundary sits at the start of reference unit ``gi``. Its
partner is the start of system unit ``hj`` when ``(gi - 1, hj - 1)`` and
``(gi, hj)`` are both aligned pairs. The start edge pairs the two first
units and the end edge the two last. Both boundaries have to pass the gate
(``gf`` and ``hf`` beside them). A partner within ``tol_s`` plus
``TA_TOL_S`` is a hit, so an error of exactly 20 ms counts. A time already
credited on either side is not credited again, as the denominators count
coincident times once.
"""
if not gu or not hu:
return 0
pairs = set(pairs)
cand = []
if (0, 0) in pairs and gf[0] and hf[0]:
cand.append((float(gu[0].start), float(hu[0].start)))
for gi, hj in sorted(pairs):
if (gi and hj and (gi - 1, hj - 1) in pairs
and gf[gi - 1] and gf[gi] and hf[hj - 1] and hf[hj]):
cand.append((float(gu[gi].start), float(hu[hj].start)))
lg, lh = len(gu) - 1, len(hu) - 1
if (lg, lh) in pairs and gf[lg] and hf[lh]:
cand.append((float(gu[lg].end), float(hu[lh].end)))
used_g, used_h, hits = set(), set(), 0
for g, h in cand:
kg, kh = round(g, 6), round(h, 6)
if kg in used_g or kh in used_h or abs(h - g) > tol_s + TA_TOL_S:
continue
used_g.add(kg)
used_h.add(kh)
hits += 1
return hits
43 changes: 43 additions & 0 deletions fabench/score/test/test_labelled_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,46 @@ def test_word_tier_substitution_is_charged():
Interval("tree", 0.2, 0.3), Interval("four", 0.3, 0.4)])
us = score_pair(gold, hyp, condition="c", aligner="a", mode="A")
assert us.wbnd_all == {"n_gold": 5, "n_hyp": 5, "hits": 3}


def test_a_boundary_is_judged_against_its_own_partner():
"""A B C with B 25 ms long, the system 15 ms late on both edges of B. Each
inner boundary is 15 ms from its partner, so all four are hits. Closest
first paired the reference B|C at 25 ms with the system A|B at 15 ms and
stranded the other two, one hit lost (issue #36)."""
gold = ivs([("a", -0.1, 0.0), ("b", 0.0, 0.025), ("c", 0.025, 0.1)])
hyp = ivs([("a", -0.1, 0.015), ("b", 0.015, 0.040), ("c", 0.040, 0.1)])
assert _all(gold, hyp) == {"n_gold": 4, "n_hyp": 4, "hits": 4}
assert _all(gold, hyp, pairing="time")["hits"] == 3


def test_a_boundary_of_another_name_never_answers():
"""A B C with B 60 ms long, the system 40 ms late on both edges of B. Both
inner boundaries miss their partners, so only the two edges are hits.
Closest first credited the reference B|C at 60 ms against the system A|B
at 40 ms, a hit the labels do not allow."""
gold = ivs([("a", -0.1, 0.0), ("b", 0.0, 0.060), ("c", 0.060, 0.2)])
hyp = ivs([("a", -0.1, 0.040), ("b", 0.040, 0.100), ("c", 0.100, 0.2)])
assert _all(gold, hyp) == {"n_gold": 4, "n_hyp": 4, "hits": 2}
assert _all(gold, hyp, pairing="time")["hits"] == 3


def test_an_error_of_exactly_20_ms_is_a_hit():
"""0.13 - 0.11 is 0.020000000000000004 in floats. The TA_TOL_S guard
counts it within 20 ms, as the word timestamp F1 already does."""
gold = ivs([("a", 0.0, 0.11), ("b", 0.11, 0.5)])
hyp = ivs([("a", 0.0, 0.13), ("b", 0.13, 0.5)])
assert _all(gold, hyp)["hits"] == 3
assert _all(gold, hyp, pairing="time")["hits"] == 2


def test_phone_partners_come_from_the_phone_alignment():
"""The phone tier takes its partners from unit_pairs. A short phone with a
steady 15 ms lag scores every boundary, as on the word tier."""
gold = ivs([("w", -0.1, 0.1)])
gph = ivs([("a", -0.1, 0.0), ("b", 0.0, 0.025), ("c", 0.025, 0.1)])
hph = ivs([("a", -0.1, 0.015), ("b", 0.015, 0.040), ("c", 0.040, 0.1)])
pm = [(0, 0), (1, 1), (2, 2)]
r = _all(gold, gold, gph, hph, gold_unit_matched={0, 1, 2},
hyp_unit_matched={0, 1, 2}, unit_pairs=pm)
assert r == {"n_gold": 4, "n_hyp": 4, "hits": 4}
2 changes: 2 additions & 0 deletions tests/repro/test_records_202610.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def rebuilt(inputs, checked, tmp_path_factory):
"subset": subset} if c == corpus
else {"enabled": False}) for c in corpora}},
"conditions": {"noise_types": [], "snr_db": [], "include_clean": True},
# October 2026 paired the gated boundary times closest first.
"scoring": {"boundary_pairing": "time"},
"aligners": [dict(yaml.safe_load((idx[n][1] / "config.yaml").read_text()),
enabled=True) for n in sorted(names)],
"paths": {"results_dir": str(tree / "summary" / kind / "en" / corpus
Expand Down
Loading