{"record":{"id":"a235ad3d7fd3aea7","repo":"keras-team/keras","slug":"all-hashedcrossing-inputs-should-be-dense-tensor","errorCode":null,"errorMessage":"All `HashedCrossing` inputs should be dense tensors. Received: inputs={inputs}","messagePattern":"All `HashedCrossing` inputs should be dense tensors\\. Received: inputs=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashed_crossing.py","lineNumber":218,"sourceCode":"\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            )\n","sourceCodeStart":200,"sourceCodeEnd":230,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashed_crossing.py#L200-L230","documentation":"HashedCrossing accepts only dense tensors. RaggedTensor or SparseTensor inputs are rejected because the crossing op needs uniform dense layout.","triggerScenarios":"Any input x for which isinstance(x, (tf.RaggedTensor, tf.SparseTensor)) is true when the layer is called.","commonSituations":"Using ragged or sparse data pipelines (NLP token batches, padded sequences) directly with HashedCrossing without densifying.","solutions":["Convert ragged inputs with x.to_tensor() (possibly after trimming/padding to (batch,1))","Convert sparse inputs with tf.sparse.to_dense(x)","Move dense conversion upstream into the tf.data pipeline"],"exampleFix":"// before\nout = layer([ragged_a, b])\n// after\ndense_a = ragged_a.to_tensor()\nout = layer([dense_a, b])","handlingStrategy":"validation","validationCode":"inputs = [x.to_tensor() if hasattr(x, \"to_tensor\") else tf.sparse.to_dense(x) if isinstance(x, tf.SparseTensor) else x for x in inputs]","typeGuard":"def all_dense(inputs):\n    import tensorflow as tf\n    return not any(isinstance(x, (tf.RaggedTensor, tf.SparseTensor)) for x in inputs)","tryCatchPattern":"catch ValueError from call() and densify inputs (x.to_tensor() / tf.sparse.to_dense(x)) before retrying","preventionTips":["Convert RaggedTensor/SparseTensor inputs to dense with to_tensor()/tf.sparse.to_dense before HashedCrossing","Do not pipe padded or ragged-batch datasets directly into a crossing layer"],"tags":["keras","hashed-crossing","sparse-tensor","ragged"],"backgroundTag":"invalid-input-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}