{"record":{"id":"05d317f1e3a82802","repo":"keras-team/keras","slug":"all-hashedcrossing-inputs-should-have-equal-shap","errorCode":null,"errorMessage":"All `HashedCrossing` inputs should have equal shape. Received: inputs={inputs}","messagePattern":"All `HashedCrossing` inputs should have equal shape\\. Received: inputs=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashed_crossing.py","lineNumber":211,"sourceCode":"                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\n            for x in inputs\n        ):\n            raise ValueError(\n                \"All `HashedCrossing` inputs should have an integer or \"\n                f\"string dtype. Received: inputs={inputs}\"\n            )","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashed_crossing.py#L193-L229","documentation":"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.","triggerScenarios":"tuple(x.shape) differing across inputs, e.g. (32, 1) vs (33, 1) or () vs (32,), reaching _check_input_shape_and_type.","commonSituations":"One feature sliced with [:-1] by accident; ragged-to-dense conversions producing different lengths; mixing inputs from different batch sources.","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"],"exampleFix":"// before\nout = layer([a, b])  # a: (32,1), b: (33,1)\n// after\nb = b[: tf.shape(a)[0]]\nout = layer([a, b])","handlingStrategy":"validation","validationCode":"s0 = tuple(inputs[0].shape)\nassert all(tuple(x.shape) == s0 for x in inputs[1:])","typeGuard":"def equal_shapes(inputs):\n    s = tuple(inputs[0].shape)\n    return all(tuple(x.shape) == s for x in inputs[1:])","tryCatchPattern":"catch ValueError from call(), align shapes with tf.reshape(x, [-1, 1]), then retry","preventionTips":["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"],"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"}