Repository navigation
fix(models): undo Moses entity escaping in MADLAD-400 output - #819
Open
ShaiShmuel wants to merge 2 commits into
Open
ShaiShmuel wants to merge 2 commits into
ShaiShmuel wants to merge 2 commits into
Conversation
For some target languages MADLAD-400 returns text in the Moses tokenizer's escaped form, for example "d ' Android" instead of "d'Android" with <2fr_CA>. The CTranslate2 adapter passed it through. Add an unescape_moses_entities load-time option to the CTranslate2 generation adapter and enable it for google/madlad400-3b-mt. It unescapes the Moses entity set in the decoded output, skips entities that occur literally in the input, and repairs spacing only for French elision and balanced quote pairs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up: - French elision is rejoined only when the prompt carries a French target tag (<2fr>, <2fr_CA>), so "Rock ' n ' Roll" in another language is unescaped but keeps its spaces. - A quoted elided letter is joined like an elision; a test pins that. - The adapter imports the helper under a private name, so the option of the same name no longer shadows it. - Docstrings state the quote-pairing rule as the code applies it and use a made-up example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ShaiShmuel
marked this pull request as ready for review
October 20, 2026 13:51
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is wrong
',"and&come back as',"and&, with a space on each side.<2fr_CA>,d'Androidcomes back asd ' Android. The same source with<2fr>comes back clean. Arabic, Hebrew and Russian outputs sometimes contain" ... "or a spaced&.Net effect: in a WMT24++ sample, 34 of 48 fr_CA translations contained
', plus a few Arabic, Hebrew and Russian outputs with"or&.Change
unescape_moses_entitiesload-time option to the CTranslate2 generation adapter. It is off by default, and we turn it on only in thegoogle/madlad400-3b-mtprofile.& < > ' " [ ] |) in the decoded output. It skips any entity that occurs literally in the input, so a request that translates&keeps it. Unescaping is a single pass, so&lt;becomes<, not<.<2fr>,<2fr_CA>):l ' offrebecomesl'offre. This covers c', d', j', l', m', n', s', t', the qu' family and aujourd'hui."pairs:" Oui "becomes"Oui".R & DbecomesR & D. An odd number of quotes, or a literal"elsewhere in the output, is not respaced.Sentences that come back joined without a space are a separate issue and are not changed here.
Tests
test_ctranslate2_moses_entities.py(new): elision, quote pairs, ambiguous quotes, the other entities, single-pass unescaping, entities present in the source, and text without entities. All test strings are synthetic.test_ctranslate2_generation.py: the option is off by default, unescapes when on, keeps an entity that the prompt contains, and rejects a non-boolean value.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes