{"record":{"id":"61c6774deb62ddeb","repo":"tensorflow/models","slug":"positionembedding-expects-a-3-dimensional-input-te","errorCode":null,"errorMessage":"PositionEmbedding expects a 3-dimensional input tensor of shape [batch, sequence, width]","messagePattern":"PositionEmbedding expects a 3-dimensional input tensor of shape \\[batch, sequence, width\\]","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/networks/packed_sequence_embedding.py","lineNumber":247,"sourceCode":"    self._max_sequence_length = max_sequence_length\n    self._initializer = tf_keras.initializers.get(initializer)\n    self._use_dynamic_slicing = use_dynamic_slicing\n\n  def get_config(self):\n    config = {\n        'max_sequence_length': self._max_sequence_length,\n        'initializer': tf_keras.initializers.serialize(self._initializer),\n        'use_dynamic_slicing': self._use_dynamic_slicing,\n    }\n    base_config = super().get_config()\n    return dict(list(base_config.items()) + list(config.items()))\n\n  def build(self, input_shape):\n    \"\"\"Implements build() for the layer.\"\"\"\n    dimension_list = input_shape.as_list()\n\n    if len(dimension_list) != 3:\n      raise ValueError('PositionEmbedding expects a 3-dimensional input tensor '\n                       'of shape [batch, sequence, width]')\n    seq_length = dimension_list[1]\n    width = dimension_list[2]\n\n    # If we are not using dynamic slicing, we must assume that the sequence\n    # length is fixed and max_sequence_length should not be specified.\n    if not self._use_dynamic_slicing:\n      if seq_length is None:\n        raise ValueError(\n            'PositionEmbedding must have `use_dynamic_slicing` set '\n            'to True (and max_sequence_length set) when the '\n            'sequence (1st) dimension of the input is None.')\n      if self._max_sequence_length is not None:\n        raise ValueError(\n            'When `use_dynamic_slicing` is False, max_sequence_length should '\n            'not be specified and we ought to use seq_length to get the '\n            'variable shape.')\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/networks/packed_sequence_embedding.py#L229-L265","documentation":"Error \"PositionEmbedding expects a 3-dimensional input tensor of shape [batch, sequence, width]\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/networks/packed_sequence_embedding.py:247 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"}