{"record":{"id":"fc94b3fcd744a860","repo":"tensorflow/models","slug":"classification-heads-should-have-unique-names","errorCode":null,"errorMessage":"Classification heads should have unique names.","messagePattern":"Classification heads should have unique names\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/models/bert_pretrainer.py","lineNumber":214,"sourceCode":"      customized_masked_lm: Optional[tf_keras.layers.Layer] = None,\n      name: str = 'bert',\n      **kwargs):\n    super().__init__(self, name=name, **kwargs)\n    self._config = {\n        'encoder_network': encoder_network,\n        'mlm_initializer': mlm_initializer,\n        'mlm_activation': mlm_activation,\n        'classification_heads': classification_heads,\n        'name': name,\n    }\n    self.encoder_network = encoder_network\n    # Makes sure the weights are built.\n    _ = self.encoder_network(self.encoder_network.inputs)\n    inputs = copy.copy(self.encoder_network.inputs)\n    self.classification_heads = classification_heads or []\n    if len(set([cls.name for cls in self.classification_heads])) != len(\n        self.classification_heads):\n      raise ValueError('Classification heads should have unique names.')\n\n    self.masked_lm = customized_masked_lm or layers.MaskedLM(\n        embedding_table=self.encoder_network.get_embedding_table(),\n        activation=mlm_activation,\n        initializer=mlm_initializer,\n        name='cls/predictions')\n    masked_lm_positions = tf_keras.layers.Input(\n        shape=(None,), name='masked_lm_positions', dtype=tf.int32)\n    if isinstance(inputs, dict):\n      inputs['masked_lm_positions'] = masked_lm_positions\n    else:\n      inputs.append(masked_lm_positions)\n    self.inputs = inputs\n\n  def call(self, inputs):  # pytype: disable=signature-mismatch  # overriding-parameter-count-checks\n    if isinstance(inputs, list):\n      logging.warning('List inputs to BertPretrainer are discouraged.')\n      inputs = dict([","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/models/bert_pretrainer.py#L196-L232","documentation":"Error \"Classification heads should have unique names.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/models/bert_pretrainer.py:214 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}