openai/whisper · error · ValueError
This model doesn't have language tokens so it can't perform
Error message
This model doesn't have language tokens so it can't perform lang id
What it means
whisper.detect_language() needs a tokenizer whose prompt sequence contains a language token (<|xx|> after <|startoftranscript|>). English-only models ('.en' checkpoints, or get_tokenizer(multilingual=False)) have no language tokens, so the check tokenizer.language_token not in sot_sequence raises ValueError before any inference.
Source
Thrown at whisper/decoding.py:42
of the most probable language tokens and the probability distribution over all language tokens.
This is performed outside the main decode loop in order to not interfere with kv-caching.
Returns
-------
language_tokens : Tensor, shape = (n_audio,)
ids of the most probable language tokens, which appears after the startoftranscript token.
language_probs : List[Dict[str, float]], length = n_audio
list of dictionaries containing the probability distribution over all languages.
"""
if tokenizer is None:
tokenizer = get_tokenizer(
model.is_multilingual, num_languages=model.num_languages
)
if (
tokenizer.language is None
or tokenizer.language_token not in tokenizer.sot_sequence
):
raise ValueError(
"This model doesn't have language tokens so it can't perform lang id"
)
single = mel.ndim == 2
if single:
mel = mel.unsqueeze(0)
# skip encoder forward pass if already-encoded audio features were given
if mel.shape[-2:] != (model.dims.n_audio_ctx, model.dims.n_audio_state):
mel = model.encoder(mel)
# forward pass using a single token, startoftranscript
n_audio = mel.shape[0]
x = torch.tensor([[tokenizer.sot]] * n_audio).to(mel.device) # [n_audio, 1]
logits = model.logits(x, mel)[:, 0]
# collect detected languages; suppress all non-language tokens
mask = torch.ones(logits.shape[-1], dtype=torch.bool)View on GitHub (pinned to 5f86d1d863)
Solutions
- Use a multilingual model: whisper.load_model('base') instead of 'base.en'
- Skip detect_language() for English-only models and hardcode language='en' in transcribe()
- Gate the call on model.is_multilingual before invoking detect_language()
Example fix
# before
model = whisper.load_model("base.en")
lang, _ = whisper.detect_language(model, mel) # ValueError
# after
model = whisper.load_model("base")
lang, _ = whisper.detect_language(model, mel)
# or keep .en model and skip detection:
# result = whisper.transcribe(model, path, language="en") Defensive patterns
Strategy: type-guard
Validate before calling
def supports_lang_id(model) -> bool:
return model.is_multilingual Type guard
from whisper import Whisper
def can_detect_language(model: Whisper) -> bool:
return bool(getattr(model, "is_multilingual", False)) Try / catch
try:
_, probs = whisper.detect_language(model, mel)
except ValueError as e:
if "language tokens" in str(e):
probs = {"en": 1.0} # English-only model: assume en
else:
raise Prevention
- Branch on model.is_multilingual before any detect_language() call
- For '.en' models always pass language='en' to transcribe()
- Centralize model selection so language-id code cannot receive English-only models
When it happens
Trigger: Calling whisper.detect_language(model) on a model loaded as 'base.en'/'large-v2.en'; or building DecodingOptions/Tokenizer manually with multilingual=False and passing it to detect_language; the code path builds a default tokenizer from model.is_multilingual and it comes back English-only.
Common situations: Switching a pipeline from 'base' to 'base.en' for speed and forgetting a detect_language() call; fine-tuned checkpoints whose dims.n_vocab reflect the English vocabulary; code that assumes every model supports lang id.
Related errors
- This tokenizer does not have language token configured
- Language {language} not found in tokenizer.
- Unsupported language: {language}
AI-assisted analysis of openai/whisper@5f86d1d863 (2026-08-14).
Data as JSON: /api/errors/70d969e57569f265.
Report an issue: GitHub.