{"record":{"id":"10488a7ede3752ca","repo":"tensorflow/models","slug":"tntransformerexpandcondense-expects-a-three-dimens","errorCode":null,"errorMessage":"TNTransformerExpandCondense expects a three-dimensional input of shape [batch, sequence, width].","messagePattern":"TNTransformerExpandCondense expects a three-dimensional input of shape \\[batch, sequence, width\\]\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/tn_transformer_expand_condense.py","lineNumber":109,"sourceCode":"    self._activity_regularizer = tf_keras.regularizers.get(activity_regularizer)\n    self._kernel_constraint = tf_keras.constraints.get(kernel_constraint)\n    self._bias_constraint = tf_keras.constraints.get(bias_constraint)\n    self._use_bias = use_bias\n    self._norm_first = norm_first\n    self._norm_epsilon = norm_epsilon\n    self._intermediate_dropout = intermediate_dropout\n    if attention_initializer:\n      self._attention_initializer = tf_keras.initializers.get(\n          attention_initializer)\n    else:\n      self._attention_initializer = tf_utils.clone_initializer(\n          self._kernel_initializer)\n\n  def build(self, input_shape):\n    input_tensor = input_shape[0] if len(input_shape) == 2 else input_shape\n    input_tensor_shape = tf.TensorShape(input_tensor)\n    if len(input_tensor_shape.as_list()) != 3:\n      raise ValueError(\n          \"TNTransformerExpandCondense expects a three-dimensional input of \"\n          \"shape [batch, sequence, width].\")\n    batch_size, sequence_length, hidden_size = input_tensor_shape\n\n    if len(input_shape) == 2:\n      mask_tensor_shape = tf.TensorShape(input_shape[1])\n      expected_mask_tensor_shape = tf.TensorShape(\n          [batch_size, sequence_length, sequence_length])\n      if not expected_mask_tensor_shape.is_compatible_with(mask_tensor_shape):\n        raise ValueError(\n            \"When passing a mask tensor to TNTransformerExpandCondense, the \"\n            \"mask tensor must be of shape [batch, \"\n            \"sequence_length, sequence_length] (here %s). Got a \"\n            \"mask tensor of shape %s.\" %\n            (expected_mask_tensor_shape, mask_tensor_shape))\n    if hidden_size % self._num_heads != 0:\n      raise ValueError(\n          \"The input size (%d) is not a multiple of the number of attention \"","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/tn_transformer_expand_condense.py#L91-L127","documentation":"Error \"TNTransformerExpandCondense expects a three-dimensional input of shape [batch, sequence, width].\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/tn_transformer_expand_condense.py:109 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"}