wav2vec2 ASR drops repeated letters ("slipper" → "sliper"): blank tokens are skipped before CTC merges repeats
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- machine-learning
Research direction
Start in AutomaticSpeechRecognitionPipeline._call_wav2vec2, where the issue says predicted IDs are decoded with special tokens skipped. Read the Python Wav2Vec2CTCTokenizer._decode behavior described here and add a regression test using repeated letters separated by the CTC blank. Done means the decoded transcript preserves those repeated letters while still skipping special tokens.
Written by the indexing model from the issue text.
Description
System Info
@huggingface/transformers 4.3.2, Node 22 and Chrome (WebGPU and wasm), same result.
Description
AutomaticSpeechRecognitionPipeline._call_wav2vec2 takes the argmax ids and decodes them with
this.tokenizer.decode(predicted_ids, { skip_special_tokens: true })
The CTC blank is the pad token, which is a special token, so it is removed before the CTC decoder merges repeated ids. The blank between two identical letters is exactly what keeps them apart, so every double letter collapses into one.
With a Danish wav2vec2 model (CoRal-project/roest-v3-wav2vec2-315m, converted to ONNX), on a FLEURS recording:
- transformers.js:
så snart du sliper ud af strømen er det ike sværere end normalt at svøme tilbage - Python, same ONNX file, greedy argmax +
Wav2Vec2CTCTokenizer.decode:så snart du slipper ud af strømmen er det ikke sværere end normalt at svømme tilbage
On 50 FLEURS sentences this is the difference between 28.4% and 21.8% WER. It affects English models just as much: Xenova/wav2vec2-base-960h has <pad> as a special added token in the same way (see the reproduction).
In Python, Wav2Vec2CTCTokenizer._decode groups repeated tokens first and only then removes the pad token and other special tokens, which is why it gets it right.
Reproduction
import { pipeline } from "@huggingface/transformers";
const asr = await pipeline("automatic-speech-recognition", "Xenova/wav2vec2-base-960h");
const { text } = await asr("https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav");
console.log(text);
gives AND SO MY FELOW AMERICAN AND NOT WHAT YOUR COUNTRY CAN DO FOR YOU ...: "fellow" loses an L.
Suggested fix
Do the CTC step in _call_wav2vec2 before decoding, as Python's tokenizer does: merge consecutive identical ids, then drop the blank (pad_token_id), then decode the rest with skip_special_tokens: true. Something like
const blank = this.model.config.pad_token_id;
const ids = predicted_ids.filter((id, i) => id !== blank && id !== predicted_ids[i - 1]);
const text = this.tokenizer.decode(ids, { skip_special_tokens: true }).trim();
Until then, a workaround is to mark the pad token as not special in the model's tokenizer.json ("special": false for <pad> in added_tokens); the CTC decoder then removes it itself, after grouping. That is what I do for the Danish model I use in Emkay (OpenVoiceOS in the browser).
I'm happy to open a PR with the fix and a test if that helps.
- Dominant language
- JavaScript
- Stars
- 16.4k
- Forks
- 1.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 10
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from huggingface/transformers.js
-
getSession: an unhandled rejection of bufferOrPathPromise ends Node when an external data download failsPossibly taken @chessing234 claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
huggingface/transformers.js#1946 · 1 comment ·
Maintainers usually reply within 1 day
-
Expose the browser build as a subpath export (./dist/transformers.web.js)Possibly taken @anshusaurav claimed this 4 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
huggingface/transformers.js#1945 · 1 comment ·
Maintainers usually reply within 1 day
-
TextStreamer drops apostrophes with WordPiece tokenizers (clean_up_tokenization_spaces)Possibly taken @erdemozkan claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
huggingface/transformers.js#1940 ·
Maintainers usually reply within 1 day
-
Image processors with shortest_edge + longest_edge upscale every image to longest_edge (DETR, YOLOS)May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
huggingface/transformers.js#1886 · 1 comment ·
Maintainers usually reply within 1 day
-
RawImage.resize in Node (sharp affine) darkens image borders: a uniform image does not stay uniformMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
huggingface/transformers.js#1885 · 1 comment ·
Maintainers usually reply within 1 day
All issues in huggingface/transformers.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
speakeasy-api/speakeasy#2159 ·
Maintainers usually reply within 1 day
-
Queued deferred selectors still run after unmountPossibly taken @LexaTang claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ianstormtaylor/slate#6375 ·
Maintainers usually reply within 1 day
-
sync cache dist/imgOpen
Difficulty 1/5 Under an hour Newbie friendliness 82/100
oleeskild/digitalgarden#435 ·