Skip to content

fix(itn): sentence-mode accuracy fixes for en, fr and de - #93

Merged
Alex-Wengg merged 2 commits into
FluidInference:mainfrom
kiranjd:fix/itn-sentence-accuracy
Oct 14, 2026
Merged

Alex-Wengg merged 2 commits into
FluidInference:mainfrom
kiranjd:fix/itn-sentence-accuracy

Conversation

@kiranjd

@kiranjd kiranjd commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

We hit these bugs while dictating with Speakmac, which uses this crate for on-device number formatting:

Spoken Before After
she is forty-six years old she is forty-six years old she is 46 years old
the thirty-second floor the thirty-second floor the 32nd floor
add one and three quarters cups of flour add 13/4 cups of flour add 1 3/4 cups of flour
wait two and a half hours wait 2 half hours wait 2 and a half hours
the score was forty two to thirty seven the score was 36:18 the score was 42 to 37
I have twenty one apples and thirty two oranges I have 21 apples 32 oranges I have 21 apples and 32 oranges
the total was three thousand nine hundred nine the total was 3900 9 the total was 3909
the meeting is at three pm. the meeting is at 03:00 p.m**..** the meeting is at 03:00 p.m.
(fr) le cent onzième jour le 100/11 jour le 111ᵉ jour
(fr) quarante pour cent 40 pour 100 40 %
(de) vierzig prozent 40 prozent 40 %

Two existing tests asserted the old output, and their comments already flagged it as a known issue: test_sentence_mixed_punctuation_and_numbers and test_sentence_itn_multiple_numbers. Both are updated.

How

  • en: hyphens count as word breaks. Cardinal spans can't start or end on "and"/"a". Mixed fractions split on "and" ("a half" stays as words). "X to Y" times need a valid hour and minute.
  • Sentence loop: removed the 4-token cardinal limit, since max_span_tokens already bounds the search. A single period right after a tagger output that already ends in "." (such as "p.m.") is dropped; ellipses are kept.
  • fr/de: a singular denominator can't take a numerator above one. Added pour cent and prozent → %.

Testing

  • cargo test: 1,172 passed, 0 failed. cargo test --features ffi: 1,180 passed. cargo fmt --all --check is clean, and cargo clippy --all-targets reports no new warnings.
  • New unit tests cover each tagger change. New sentence-level tests in en_tests.rs and multilang_itn_tests.rs cover every row in the table above.
  • examples/parity against NeMo at the pinned ref 1f12635 (tests/parity_baseline.tsv updated):
    • fr ITN ordinal goes from 22/23 to 23/23, which brings fr ITN overall from 306/307 to 307/307.
    • Every other language and class is unchanged, including all TN classes.

Scope

  • No public API, FFI or wasm changes. All of this is default-path behaviour.
  • Happy to split this into per-language PRs if that's easier to review.

🤖 Generated with Claude Code

Handle hyphenated numbers, mixed fractions, "oh" digit sequences and
long cardinals; stop fabricating times from ranges and dropping "and"
between quantities; avoid a doubled period after p.m.; read "cent
onzième" as an ordinal; add "pour cent" and "prozent" percentages.
@Alex-Wengg

Copy link
Copy Markdown
Member

Thanks, this reproduces cleanly here and the parity run is clean. One blocker: the "oh" branch in parse_span turns bare times into digits in sentence mode ("meet me at nine oh five" → "905", main gives "09:05"), while single-expression mode still gives 09:05. Could you drop that branch and its test from this PR (room numbers need preceding-token context, happy to take that as a follow-up) and refresh tests/parity_baseline.tsv for the fr ordinal 22→23? The rest looks good to merge.

The branch read bare times as digits ("nine oh five" -> "905").
Room numbers need preceding-token context; leave that for a follow-up.
Add a regression test for the time case and record fr ITN ordinal 23/23.
@kiranjd

kiranjd commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for catching that. Pushed 7bfaee7:

  • Dropped the "oh" branch and its test. Added test_sentence_oh_time_stays_a_time
  • Refreshed tests/parity_baseline.tsv
  • cargo test: 1,172 passed

@Alex-Wengg
Alex-Wengg merged commit 2b37cd5 into FluidInference:main Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants