wav2vec2 ASR drops repeated letters ("slipper" → "sliper"): blank tokens are skipped before CTC merges repeats

Open Beginner friendly
#1,947 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@chessing234 is already working on this.

Since Nov 20, 2026.

  • #1957 by @chessing234 — open

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

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from huggingface/transformers.js

All issues in huggingface/transformers.js

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.