{"record":{"id":"040bcc799574cd39","repo":"tensorflow/models","slug":"expect-rank-for-target-shape-but-got-none-040bcc","errorCode":null,"errorMessage":"Expect rank for target shape, but got None.","messagePattern":"Expect rank for target shape, but got None\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/ops/decoding_module.py","lineNumber":101,"sourceCode":"\n\ndef expand_to_same_rank(tensor, target):\n  \"\"\"Expands a given tensor to target's rank to be broadcastable.\n\n  Args:\n    tensor: input tensor to tile. Shape: [b, d1, ..., da]\n    target: target tensor. Shape: [b, d1, ..., da, ..., dn]\n\n  Returns:\n    Tiled tensor of shape [b, d1, ..., da, 1, ..., 1] with same rank of target\n\n  Raises:\n    ValueError, if the shape rank of rank tensor/target is None.\n  \"\"\"\n  if tensor.shape.rank is None:\n    raise ValueError(\"Expect rank for tensor shape, but got None.\")\n  if target.shape.rank is None:\n    raise ValueError(\"Expect rank for target shape, but got None.\")\n\n  with tf.name_scope(\"expand_rank\"):\n    diff_rank = target.shape.rank - tensor.shape.rank\n    for _ in range(diff_rank):\n      tensor = tf.expand_dims(tensor, -1)\n    return tensor\n\n\nclass DecodingModule(tf.Module, metaclass=abc.ABCMeta):\n  \"\"\"A base class for the API required for decoding (go/decoding-tf-nlp).\"\"\"\n\n  def __init__(self,\n               length_normalization_fn: Callable[[int, tf.DType], float],\n               dtype: tf.DType = tf.float32,\n               decoding_name: Optional[str] = None,\n               extra_cache_output: bool = False):\n    \"\"\"Initialize the Decoding Module.\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/ops/decoding_module.py#L83-L119","documentation":"Error \"Expect rank for target shape, but got None.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/ops/decoding_module.py:101 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"}