Fixed: "Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend"
A fill-mask pipeline with ModernBERT worked, but printed Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend first. The model's tokenizer settings ask for a text cleanup that Transformers 5 deliberately skips for this kind of tokenizer, and the warning says so. Loading the tokenizer yourself with clean_up_tokenization_spaces=False gives the same results without the warning.
What I Was Doing
I was predicting a missing word with answerdotai/ModernBERT-base, a fill-mask model, in Transformers 5.26.0 on Python 3.14:
from transformers import pipeline
unmasker = pipeline(
"fill-mask",
model="answerdotai/ModernBERT-base",
revision="8949b909ec900327062f0ebf497f51aef5e6f0c8",
)
for guess in unmasker("The capital of France is [MASK]."):
print(f"{guess['token_str']:<10}{guess['score']:.3f}")
uv run python fill_mask.py
What I Expected
The pipeline's five guesses for the missing word, each with its score.
What I Got
Loading weights: 100%|██████████████████████████████████████████| 137/137 [00:00<00:00, 4434.72it/s]
[transformers] Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend. The clean_up_tokenization post-processing step is designed for WordPiece tokenizers and is destructive for BPE (it strips spaces before punctuation). Set clean_up_tokenization_spaces=False to suppress this warning, or set clean_up_tokenization_spaces_for_bpe_even_though_it_will_corrupt_output=True to force cleanup anyway.
Paris 0.923
Lyon 0.036
Nancy 0.023
Nice 0.006
Orleans 0.003

The guesses came, and they're good. The warning came before them. The guesses also start with a space ( Paris): that's how this tokenizer stores a word that follows a space, and it's not what the warning is about.
What I Checked
Where the setting comes from. I never set clean_up_tokenization_spaces. The model's tokenizer_config.json on the Hub does:
"clean_up_tokenization_spaces": true,
What the cleanup does. The warning comes from the tokenizer's decode, in transformers/tokenization_utils_tokenizers.py, which the fill-mask pipeline calls to turn each guessed token back into text. When the setting is on and the tokenizer is a BPE (byte-pair encoding) tokenizer, as ModernBERT's is, Transformers skips the cleanup and warns once:
if clean_up_tokenization_spaces:
# Skip cleanup for BPE tokenizers — the cleanup was designed for
# WordPiece tokenizers and is destructive for BPE (it strips
# legitimate spaces before punctuation).
if (
type(self.backend_tokenizer.model).__name__ == "BPE"
and not self.clean_up_tokenization_spaces_for_bpe_even_though_it_will_corrupt_output
):
logger.warning_once(
"Ignoring clean_up_tokenization_spaces=True for BPE tokenizer"
# ...
)
else:
text = self.clean_up_tokenization(text)
Why it was added. The pull request that added it, huggingface/transformers#44915, explains that the cleanup "applies English-specific string replacements" made for BERT-era WordPiece tokenizers, which decoded text as "Hello , world .". BPE tokenizers keep spaces inside their tokens, so for them the cleanup "is actively destructive — it strips legitimate spaces from correctly decoded text. For example, "x != y" becomes "x!= y"." Many models still have the setting on in their configuration, so the library ignores it for BPE tokenizers and warns.
Why It Happens
ModernBERT's tokenizer configuration turns the cleanup on. Transformers 5 refuses to apply it to a BPE tokenizer, because it would damage the text, and warns that it's ignoring the setting. Nothing is wrong with the results: the warning is about a setting that has no effect.
The Fix
Load the tokenizer yourself with the setting turned off, and give it to the pipeline:
from transformers import AutoTokenizer, pipeline
MODEL = "answerdotai/ModernBERT-base"
REVISION = "8949b909ec900327062f0ebf497f51aef5e6f0c8"
tokenizer = AutoTokenizer.from_pretrained(
MODEL, revision=REVISION, clean_up_tokenization_spaces=False
)
unmasker = pipeline("fill-mask", model=MODEL, revision=REVISION, tokenizer=tokenizer)
for guess in unmasker("The capital of France is [MASK]."):
print(f"{guess['token_str']:<10}{guess['score']:.3f}")

AutoTokenizer.from_pretrained(...)loads the model's tokenizer from the same commit as the model. A setting passed here,clean_up_tokenization_spaces=False, replaces the one in the model'stokenizer_config.json.tokenizer=tokenizermakes the pipeline use this tokenizer instead of loading its own.MODELandREVISIONkeep the two loads on the same model and commit.
After the Fix
uv run python fill_mask.py
Loading weights: 100%|█████████████████████████████████████████| 137/137 [00:00<00:00, 15494.25it/s]
Paris 0.923
Lyon 0.036
Nancy 0.023
Nice 0.006
Orleans 0.003

The warning is gone, and the guesses and scores are exactly the same, because the cleanup was being skipped all along. The commands work unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Setting clean_up_tokenization_spaces_for_bpe_even_though_it_will_corrupt_output=True to make it quiet | The warning goes, but the cleanup now runs and can remove real spaces from the text | Set clean_up_tokenization_spaces=False |
| Loading the tokenizer from another commit than the model | The tokenizer and the model may not match | Pass the same revision to both |
Stripping the leading space from token_str to "fix" the warning | The space has nothing to do with it | Use .strip() only when you display the word |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
The same warning with TokenizersBackend from another model | Its tokenizer configuration has the same setting | The same fix, with that model's name |
The warning comes from your own tokenizer.decode(...) call | The same setting, on a tokenizer you loaded | Load it with clean_up_tokenization_spaces=False, or pass the same argument to decode |
FAQ
Is my output wrong while the warning shows?
No. The warning says Transformers is ignoring the setting. Here the five guesses and their scores were identical with and without it.
Should the model's configuration be changed instead?
That's up to each model's authors. The pull request that added the warning chose a fix in the library because the setting is in many models' configurations.
Conclusion
Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend meant ModernBERT's tokenizer configuration asks for a cleanup that Transformers 5 skips for BPE tokenizers. Loading the tokenizer with clean_up_tokenization_spaces=False and passing it to the pipeline removed the warning and changed nothing in the results.
Additional Resources
- huggingface/transformers#44915 — the change that added the warning, with the reasons.
- Tokenizers — loading and using tokenizers in Transformers.
- answerdotai/ModernBERT-base — the model's card.
