keras-team/keras · error · ValueError
All `HashedCrossing` inputs should have equal shape…
Error message
All `HashedCrossing` inputs should have equal shape. Received: inputs={inputs} What it means
HashedCrossing implements crossing via tf.sparse.cross, which requires all input features to share shape (), (batch_size,) or (batch_size, 1). This check in _check_input_shape_and_type rejects any input whose rank or last dimension does not match that pattern.
Solutions
- Align shapes before the layer, usually tf.reshape(x, [-1, 1]) for every input
- Verify upstream batching/slicing yields the same batch size for each crossed feature
- In Functional models, use identically-shaped Input layers
Example fix
// before out = layer([a, b]) # a: (32,1), b: (33,1) // after b = b[: tf.shape(a)[0]] out = layer([a, b])
Defensive patterns
Strategy: validation
Validate before calling
s0 = tuple(inputs[0].shape) assert all(tuple(x.shape) == s0 for x in inputs[1:])
Type guard
def equal_shapes(inputs):
s = tuple(inputs[0].shape)
return all(tuple(x.shape) == s for x in inputs[1:]) Try / catch
catch ValueError from call(), align shapes with tf.reshape(x, [-1, 1]), then retry
Prevention
- Ensure all crossed features have equal shapes (and batch sizes) before the layer
- Verify upstream slicing does not drop or add a batch dimension for one feature
When it happens
Trigger: tuple(x.shape) differing across inputs, e.g. (32, 1) vs (33, 1) or () vs (32,), reaching _check_input_shape_and_type.
Common situations: One feature sliced with [:-1] by accident; ragged-to-dense conversions producing different lengths; mixing inputs from different batch sources.
Related errors
- All `HashedCrossing` inputs should have shape `()`…
- Expected as input a list/tuple of 2 tensors. Received…
- Expected the two input tensors to have identical shapes…
- All `HashedCrossing` inputs should be dense tensors…
- All `HashedCrossing` inputs should have an integer or…
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/05d317f1e3a82802.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/hashed_crossing.py:211
f"inputs. Received: inputs={inputs}"
)
if len(inputs) < 2:
raise ValueError(
"`HashedCrossing` should be called on at least two inputs. "
f"Received: inputs={inputs}"
)
def _check_input_shape_and_type(self, inputs):
first_shape = tuple(inputs[0].shape)
rank = len(first_shape)
if rank > 2 or (rank == 2 and first_shape[-1] != 1):
raise ValueError(
"All `HashedCrossing` inputs should have shape `()`, "
"`(batch_size)` or `(batch_size, 1)`. "
f"Received: inputs={inputs}"
)
if not all(tuple(x.shape) == first_shape for x in inputs[1:]):
raise ValueError(
"All `HashedCrossing` inputs should have equal shape. "
f"Received: inputs={inputs}"
)
if any(
isinstance(x, (tf.RaggedTensor, tf.SparseTensor)) for x in inputs
):
raise ValueError(
"All `HashedCrossing` inputs should be dense tensors. "
f"Received: inputs={inputs}"
)
if not all(
tf.as_dtype(x.dtype).is_integer or x.dtype == tf.string
for x in inputs
):
raise ValueError(
"All `HashedCrossing` inputs should have an integer or "
f"string dtype. Received: inputs={inputs}"
)View on GitHub (pinned to 7a34a03db6)