{"record":{"id":"0352234ff7c917b1","repo":"keras-team/keras","slug":"all-hashedcrossing-inputs-should-have-shape","errorCode":null,"errorMessage":"All `HashedCrossing` inputs should have shape `()`, `(batch_size)` or `(batch_size, 1)`. Received: inputs={inputs}","messagePattern":"All `HashedCrossing` inputs should have shape `\\(\\)`, `\\(batch_size\\)` or `\\(batch_size, 1\\)`\\. Received: inputs=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashed_crossing.py","lineNumber":205,"sourceCode":"        }\n\n    def _check_at_least_two_inputs(self, inputs):\n        if not isinstance(inputs, (list, tuple)):\n            raise ValueError(\n                \"`HashedCrossing` should be called on a list or tuple of \"\n                f\"inputs. Received: inputs={inputs}\"\n            )\n        if len(inputs) < 2:\n            raise ValueError(\n                \"`HashedCrossing` should be called on at least two inputs. \"\n                f\"Received: inputs={inputs}\"\n            )\n\n    def _check_input_shape_and_type(self, inputs):\n        first_shape = tuple(inputs[0].shape)\n        rank = len(first_shape)\n        if rank > 2 or (rank == 2 and first_shape[-1] != 1):\n            raise ValueError(\n                \"All `HashedCrossing` inputs should have shape `()`, \"\n                \"`(batch_size)` or `(batch_size, 1)`. \"\n                f\"Received: inputs={inputs}\"\n            )\n        if not all(tuple(x.shape) == first_shape for x in inputs[1:]):\n            raise ValueError(\n                \"All `HashedCrossing` inputs should have equal shape. \"\n                f\"Received: inputs={inputs}\"\n            )\n        if any(\n            isinstance(x, (tf.RaggedTensor, tf.SparseTensor)) for x in inputs\n        ):\n            raise ValueError(\n                \"All `HashedCrossing` inputs should be dense tensors. \"\n                f\"Received: inputs={inputs}\"\n            )\n        if not all(\n            tf.as_dtype(x.dtype).is_integer or x.dtype == tf.string","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashed_crossing.py#L187-L223","documentation":"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.","triggerScenarios":"An input with rank > 2, or rank 2 whose last dimension != 1 (e.g. shape (batch, 5)) reaching _check_input_shape_and_type.","commonSituations":"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.","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)"],"exampleFix":"// before\nout = layer([a, b])  # a.shape == (None, 3)\n// after\na = keras.layers.Reshape((1,))(a)  # or select/slice to one column first\nout = layer([a, b])","handlingStrategy":"validation","validationCode":"for x in inputs:\n    assert len(x.shape) <= 1 or (len(x.shape) == 2 and int(x.shape[-1]) == 1)","typeGuard":"def acceptable_shape(t):\n    s = tuple(t.shape)\n    return len(s) <= 1 or (len(s) == 2 and s[-1] == 1)","tryCatchPattern":"catch ValueError from call() and reshape each input to (batch, 1) with tf.reshape(x, [-1, 1]) before retrying","preventionTips":["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"],"tags":["keras","hashed-crossing","shape"],"backgroundTag":"shape-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}