keras-team/keras · error · ValueError

All `HashedCrossing` inputs should have equal shape. Receive

Error message

All `HashedCrossing` inputs should have equal shape. Received: inputs={inputs}

What it means

All inputs to HashedCrossing must share the same shape so they can be zipped per sample. Inputs differing in any dimension (including batch size) are rejected.

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)

Solutions

  1. Align shapes before the layer, usually tf.reshape(x, [-1, 1]) for every input
  2. Verify upstream batching/slicing yields the same batch size for each crossed feature
  3. 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

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


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/05d317f1e3a82802. Report an issue: GitHub.