Basics · num_beams 1 / 2 / 4 · elision & accent tokenization · Apache-2.0

Inside OPUS-MT FR→EN: Beam Search, Elision & Subword Fertility

French packs grammar into tiny clitics — l', qu', n', d' — and pre-verbal pronoun clusters (je le lui ai donné). Run the same sentence through greedy (num_beams=1) and beam search (num_beams=2 and 4, the model card default) on the exact same Xenova/opus-mt-fr-en weights (107.47 MB WASM q8, Apache-2.0), then inspect how the live SentencePiece tokenizer cuts elisions, accents and compound nouns.

1. Live Beam Ladder: num_beams 1 → 2 → 4

Choose a French grammar challenge or type your own sentence:

Greedy k=1–
Beam k=2–
Beam k=4–
k=4 / k=1 latency–
Words changed 1→4–
NaN check–

Greedy (num_beams = 1)

Highest-probability token at every step.

Initialise OPUS-MT FR→EN above to run the ladder.

Beam (num_beams = 2)

Keeps the 2 best partial hypotheses.

Beam-2 output will appear here.

Beam (num_beams = 4)

Model-card default: 4 hypotheses.

Beam-4 output will appear here.

Word diff: greedy → beam 2

Run the ladder to compare.

Word diff: greedy → beam 4

Run the ladder to compare.

Strikethrough = only in the greedy output · Highlighted = chosen by beam search.

2. Elision, Accent & Compound Tokenizer Inspector

What am I looking at? analyzeFrenchText() finds the elided clitics (l', qu', jusqu'…), hyphenated compounds and accented words in your sentence; each is then sent through the model's real 59,514-piece SentencePiece tokenizer in the worker. Elisions are tokenized twice — with the straight ' you type on a keyboard and the typographic ’ French publishers use. In this ONNX export ’ is not in the vocabulary and the converted Unigram tokenizer's unk_id is 2 — the id of the , piece — so a curly apostrophe reaches the encoder as a comma. The Practical page normalises ’ → ' for exactly this reason.

Subword statistics will appear once the ladder finishes.

Waiting for live tokenization…

3. Inspect the Decoding & Tokenizer Code

Show the code — worker.js compareBeams(): num_beams 1 / 2 / 4 ladder in one epoch-guarded pass
Show the code — worker.js tokenizeWords(): live SentencePiece pieces for individual French words
Show the code — opus-fr-core.mjs analyzeFrenchText(): elision, accent & hyphenated-compound detector
Show the code — opus-fr-core.mjs computeWordDiff(): deterministic word-level LCS diff