hankcs/HanLP · error · ValueError
You cannot specify both input_ids and inputs_embeds at the s
Error message
You cannot specify both input_ids and inputs_embeds at the same time
What it means
CategoricalAccuracy supports tie_break (handling multiple classes sharing the max predicted score as correct) only when scoring the single top prediction (top_k=1). Enabling tie_break with top_k > 1 is a contradictory configuration and raises ValueError at construction.
Source
Thrown at hanlp/components/amr/amrbart/model_interface/modeling_bart.py:789
than the model's internal embedding lookup matrix.
output_attentions (`bool`, *optional*):
Whether or not to return the attentions tensors of all attention layers. See `attentions` under
returned tensors for more detail.
output_hidden_states (`bool`, *optional*):
Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
for more detail.
return_dict (`bool`, *optional*):
Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
"""
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
output_hidden_states = (
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
)
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
# retrieve input_ids and inputs_embeds
if input_ids is not None and inputs_embeds is not None:
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
elif input_ids is not None:
input_shape = input_ids.size()
input_ids = input_ids.view(-1, input_shape[-1])
elif inputs_embeds is not None:
input_shape = inputs_embeds.size()[:-1]
else:
raise ValueError("You have to specify either input_ids or inputs_embeds")
if inputs_embeds is None:
inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale
embed_pos = self.embed_positions(input_shape)
hidden_states = inputs_embeds + embed_pos
hidden_states = self.layernorm_embedding(hidden_states)
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
# expand attention_maskView on GitHub (pinned to ddb1299bdd)
Solutions
- Set top_k=1 when tie_break=True
- Disable tie_break if you need top_k > 1 scoring
- Use a different metric for tie-aware top-k evaluation
Example fix
# before metric = CategoricalAccuracy(top_k=5, tie_break=True) # after metric = CategoricalAccuracy(top_k=5, tie_break=False)
Defensive patterns
Strategy: validation
Validate before calling
assert not (top_k > 1 and tie_break), 'tie_break requires top_k == 1'
Try / catch
try:
m = CategoricalAccuracy(top_k=top_k, tie_break=tie_break)
except ValueError:
m = CategoricalAccuracy(top_k=top_k, tie_break=False) Prevention
- Keep tie_break=False in top-k experiments
- Centralize metric config validation
When it happens
Trigger: Constructing CategoricalAccuracy(top_k=5, tie_break=True).
Common situations: Copy-pasting metric configs and toggling both flags; enabling tie_break to fix ambiguous predictions while leaving top_k from a previous top-k experiment.
Understand the failure class
Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.
Related errors
- You have to specify either input_ids or inputs_embeds
- Unsupported argument type: {item}
- Unrecognized mapper type {mapper}
- self.model.config.pad_token_id has to be defined.
- embed_dim must be divisible by num_heads (got `embed_dim`: {
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/289fb0dda3619279.
Report an issue: GitHub.