tensorflow/models · error · ValueError
Expect rank for target shape, but got None.
Error message
Expect rank for target shape, but got None.
What it means
Error "Expect rank for target shape, but got None." thrown in tensorflow/models.
Source
Thrown at official/nlp/modeling/ops/beam_search.py:93
def _expand_to_same_rank(tensor, target):
"""Expands a given tensor to target's rank to be broadcastable.
Args:
tensor: input tensor to tile. Shape: [b, d1, ..., da]
target: target tensor. Shape: [b, d1, ..., da, ..., dn]
Returns:
Tiled tensor of shape [b, d1, ..., da, 1, ..., 1] with same rank of target.
Raises:
ValueError, if the shape rank of rank tensor/target is None.
"""
if tensor.shape.rank is None:
raise ValueError("Expect rank for tensor shape, but got None.")
if target.shape.rank is None:
raise ValueError("Expect rank for target shape, but got None.")
with tf.name_scope("expand_rank"):
diff_rank = target.shape.rank - tensor.shape.rank
for _ in range(diff_rank):
tensor = tf.expand_dims(tensor, -1)
return tensor
class SequenceBeamSearch(tf.Module):
"""Implementation of beam search loop."""
def __init__(
self,
symbols_to_logits_fn,
vocab_size,
beam_size,
alpha,
max_decode_length,View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/nlp/modeling/ops/beam_search.py:93 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/4d920721f49fb9de.
Report an issue: GitHub.