huggingface/transformers · error · ValueError
Each list in `bad_words_ids` has to be a list of positive in
Error message
Each list in `bad_words_ids` has to be a list of positive integers, but is {bad_words_ids}. What it means
Error "Each list in `bad_words_ids` has to be a list of positive integers, but is {bad_words_ids}." thrown in huggingface/transformers.
Source
Thrown at src/transformers/generation/logits_process.py:1479
eos_token_id_list = eos_token_id.tolist() # convert to python list before
bad_words_ids = list(
filter(lambda bad_token_seq: all(bad_token_seq != [i] for i in eos_token_id_list), bad_words_ids)
)
# Forbidding a sequence is equivalent to setting its bias to -inf
sequence_bias = {tuple(sequence): float("-inf") for sequence in bad_words_ids}
super().__init__(sequence_bias=sequence_bias)
def _validate_arguments(self):
bad_words_ids = self.bad_word_ids
if not isinstance(bad_words_ids, list) or len(bad_words_ids) == 0:
raise ValueError(f"`bad_words_ids` has to be a non-empty list, but is {bad_words_ids}.")
if any(not isinstance(bad_word_ids, list) for bad_word_ids in bad_words_ids):
raise ValueError(f"`bad_words_ids` has to be a list of lists, but is {bad_words_ids}.")
if any(
any((not isinstance(token_id, (int, np.integer)) or token_id < 0) for token_id in bad_word_ids)
for bad_word_ids in bad_words_ids
):
raise ValueError(
f"Each list in `bad_words_ids` has to be a list of positive integers, but is {bad_words_ids}."
)
class PrefixConstrainedLogitsProcessor(LogitsProcessor):
r"""
[`LogitsProcessor`] that enforces constrained generation and is useful for prefix-conditioned constrained
generation. See [Autoregressive Entity Retrieval](https://huggingface.co/papers/2010.00904) for more information.
Args:
prefix_allowed_tokens_fn (`Callable[[int, torch.Tensor], list[int]]`):
This function constraints the beam search to allowed tokens only at each step. This function takes 2
arguments `inputs_ids` and the batch ID `batch_id`. It has to return a list with the allowed tokens for the
next generation step conditioned on the previously generated tokens `inputs_ids` and the batch ID
`batch_id`.
Examples:
View on GitHub (pinned to a597f97485)
Solutions
- Ensure every entry in `bad_words_ids` contains only positive integer token ids.
- Filter out negative or non-integer values before passing the list.
When it happens
Trigger: Raised in NoBadWordsLogitsProcessor.__init__ when an inner bad_words_ids list is empty or contains non-positive-integer token ids.
Common situations: Banned phrase lists containing negative ids, floats, or empty entries after tokenization of bad words.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/8436f75f85a5bfe2.
Report an issue: GitHub.