huggingface/transformers · error · ValueError
`sequence_bias` has to be a dict with floats as values, but
Error message
`sequence_bias` has to be a dict with floats as values, but is {sequence_bias}. What it means
Error "`sequence_bias` has to be a dict with floats as values, but is {sequence_bias}." thrown in huggingface/transformers.
Source
Thrown at src/transformers/generation/logits_process.py:1386
f"{sequence_bias}."
)
def all_token_bias_pairs_are_valid(sequence):
return (
isinstance(sequence[0], list)
and all(isinstance(token_id, (int, np.integer)) and token_id > 0 for token_id in sequence[0])
and isinstance(sequence[1], float)
)
if isinstance(sequence_bias, list) and any(
(not all_token_bias_pairs_are_valid(sequence)) or len(sequence) == 0 for sequence in sequence_bias
):
raise ValueError(
f"Each element in `sequence_bias` has to be a non-empty list of lists of positive integers and float, but is "
f"{sequence_bias}."
)
if isinstance(sequence_bias, dict) and any(not isinstance(bias, float) for bias in sequence_bias.values()):
raise ValueError(f"`sequence_bias` has to be a dict with floats as values, but is {sequence_bias}.")
def _convert_list_arguments_into_dict(self):
"""BC: we used to accept `dict{tuple of tokens: float}` directly, now we expect a list"""
if isinstance(self.sequence_bias, list):
temp_sequence = self.sequence_bias
self.sequence_bias = {tuple(sublist[0]): sublist[1] for sublist in temp_sequence}
class NoBadWordsLogitsProcessor(SequenceBiasLogitsProcessor):
"""
[`LogitsProcessor`] that enforces that specified sequences will never be selected.
<Tip>
In order to get the token ids of the words that should not appear in the generated text, make sure to set
`add_prefix_space=True` when initializing the tokenizer, and use `tokenizer(bad_words,
add_special_tokens=False).input_ids`. The `add_prefix_space` argument is only supported for some slow tokenizers,
as fast tokenizers' prefixing behaviours come from `pre tokenizers`. Read moreView on GitHub (pinned to a597f97485)
Solutions
- Ensure all values in `sequence_bias` are floats (or ints convertible to float).
- Remove non-numeric bias values from the dict.
When it happens
Trigger: Raised in SequenceBiasLogitsProcessor.__init__ when a sequence_bias dict value is not a float bias.
Common situations: Passing ints, strings, or None as bias values in sequence_bias instead of floats.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/c9aed2cdd07f994c.
Report an issue: GitHub.