{"record":{"id":"289fb0dda3619279","repo":"hankcs/HanLP","slug":"you-cannot-specify-both-input-ids-and-inputs-embed","errorCode":null,"errorMessage":"You cannot specify both input_ids and inputs_embeds at the same time","messagePattern":"You cannot specify both input_ids and inputs_embeds at the same time","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/components/amr/amrbart/model_interface/modeling_bart.py","lineNumber":789,"sourceCode":"                than the model's internal embedding lookup matrix.\n            output_attentions (`bool`, *optional*):\n                Whether or not to return the attentions tensors of all attention layers. See `attentions` under\n                returned tensors for more detail.\n            output_hidden_states (`bool`, *optional*):\n                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors\n                for more detail.\n            return_dict (`bool`, *optional*):\n                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n        \"\"\"\n        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions\n        output_hidden_states = (\n            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states\n        )\n        return_dict = return_dict if return_dict is not None else self.config.use_return_dict\n\n        # retrieve input_ids and inputs_embeds\n        if input_ids is not None and inputs_embeds is not None:\n            raise ValueError(\"You cannot specify both input_ids and inputs_embeds at the same time\")\n        elif input_ids is not None:\n            input_shape = input_ids.size()\n            input_ids = input_ids.view(-1, input_shape[-1])\n        elif inputs_embeds is not None:\n            input_shape = inputs_embeds.size()[:-1]\n        else:\n            raise ValueError(\"You have to specify either input_ids or inputs_embeds\")\n\n        if inputs_embeds is None:\n            inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale\n\n        embed_pos = self.embed_positions(input_shape)\n\n        hidden_states = inputs_embeds + embed_pos\n        hidden_states = self.layernorm_embedding(hidden_states)\n        hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)\n\n        # expand attention_mask","sourceCodeStart":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/model_interface/modeling_bart.py#L771-L807","documentation":"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.","triggerScenarios":"Constructing CategoricalAccuracy(top_k=5, tie_break=True).","commonSituations":"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.","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"],"exampleFix":"# before\nmetric = CategoricalAccuracy(top_k=5, tie_break=True)\n# after\nmetric = CategoricalAccuracy(top_k=5, tie_break=False)","handlingStrategy":"validation","validationCode":"assert not (top_k > 1 and tie_break), 'tie_break requires top_k == 1'","typeGuard":null,"tryCatchPattern":"try:\n    m = CategoricalAccuracy(top_k=top_k, tie_break=tie_break)\nexcept ValueError:\n    m = CategoricalAccuracy(top_k=top_k, tie_break=False)","preventionTips":["Keep tie_break=False in top-k experiments","Centralize metric config validation"],"tags":["hanlp","metrics","accuracy","config-validation"],"backgroundTag":"config-validation-failed","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}