huggingface
config_error
ai_generated
true
ValueError: Adding special tokens to a tokenizer that already has them; use `add_special_tokens=True` only if you intend to add new tokens. Got extra_ids=0 but tokenizer already has 2 special tokens.
ID: huggingface/tokenizer-extra-special-tokens-invalid
90%Fix Rate
84%Confidence
1Evidence
2024-05-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| tokenizers 0.19.1 | active | — | — | — |
| transformers 4.44.0 | active | — | — | — |
Root Cause
User called `tokenizer.add_special_tokens()` with an empty or redundant special tokens dictionary, but the tokenizer already has those tokens defined, causing a validation error.
generic中文
用户使用空的或冗余的特殊标记字典调用了 `tokenizer.add_special_tokens()`,但分词器已定义这些标记,导致验证错误。
Official Documentation
https://huggingface.co/docs/tokenizers/en/api/special-tokensWorkarounds
-
90% success Check existing special tokens before adding: if `tokenizer.special_tokens_map` already contains the tokens, skip the `add_special_tokens` call entirely.
Check existing special tokens before adding: if `tokenizer.special_tokens_map` already contains the tokens, skip the `add_special_tokens` call entirely.
-
85% success Use `tokenizer.add_special_tokens({'additional_special_tokens': ['<new_token>']})` only for truly new tokens, not duplicates.
Use `tokenizer.add_special_tokens({'additional_special_tokens': ['<new_token>']})` only for truly new tokens, not duplicates.
中文步骤
Check existing special tokens before adding: if `tokenizer.special_tokens_map` already contains the tokens, skip the `add_special_tokens` call entirely.
Use `tokenizer.add_special_tokens({'additional_special_tokens': ['<new_token>']})` only for truly new tokens, not duplicates.
Dead Ends
Common approaches that don't work:
-
100% fail
The parameter `add_special_tokens` controls whether to add tokens to the vocabulary, not whether to check for duplicates; the error persists.
-
40% fail
Deleting built-in special tokens (like [CLS], [SEP]) can break tokenizer functionality; re-adding may still fail if they are already present in the base tokenizer.