keras-team/keras · error · ValueError
All `HashedCrossing` inputs should have shape `()`, `(batch_
Error message
All `HashedCrossing` inputs should have shape `()`, `(batch_size)` or `(batch_size, 1)`. Received: inputs={inputs} What it means
HashedCrossing only accepts scalar per-sample inputs: shape (), (batch_size,) or (batch_size, 1). Tensors with rank > 2, or rank 2 with last dimension != 1, are rejected because each sample must contribute exactly one value to the crossing.
Source
Thrown at keras/src/layers/preprocessing/hashed_crossing.py:205
}
def _check_at_least_two_inputs(self, inputs):
if not isinstance(inputs, (list, tuple)):
raise ValueError(
"`HashedCrossing` should be called on a list or tuple of "
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.stringView on GitHub (pinned to 7a34a03db6)
Solutions
- Reshape each input to (batch,) or (batch, 1): tf.reshape(x, [-1]) or [-1, 1]
- Reduce multi-value features to a single value before crossing (e.g. take the first token or aggregate)
- Check upstream layers (Embedding, dense features) are not producing (batch, k>1)
Example fix
// before out = layer([a, b]) # a.shape == (None, 3) // after a = keras.layers.Reshape((1,))(a) # or select/slice to one column first out = layer([a, b])
Defensive patterns
Strategy: validation
Validate before calling
for x in inputs:
assert len(x.shape) <= 1 or (len(x.shape) == 2 and int(x.shape[-1]) == 1) Type guard
def acceptable_shape(t):
s = tuple(t.shape)
return len(s) <= 1 or (len(s) == 2 and s[-1] == 1) Try / catch
catch ValueError from call() and reshape each input to (batch, 1) with tf.reshape(x, [-1, 1]) before retrying
Prevention
- Reshape scalar or multi-column features to shape (batch,) or (batch, 1) before HashedCrossing
- Cross single-valued features only; multi-value features need reduction first
When it happens
Trigger: An input with rank > 2, or rank 2 whose last dimension != 1 (e.g. shape (batch, 5)) reaching _check_input_shape_and_type.
Common situations: Feeding multi-column features shape (batch, n>1); feeding 3D tensors from sequence pipelines; forgetting to slice a wide DataFrame column set down to one value.
Related errors
- Expected as input a list/tuple of 2 tensors. Received input_
- Expected the two input tensors to have identical shapes. Rec
- All `HashedCrossing` inputs should have equal shape. Receive
- Layer {self.name} weight shape {variable.shape} is not compa
- Expected rebatched data to have batch size 1. Received: shap
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/0352234ff7c917b1.
Report an issue: GitHub.