{"record":{"id":"f57a4d7843fe2550","repo":"keras-team/keras","slug":"expected-the-two-input-tensors-to-have-identical-s","errorCode":null,"errorMessage":"Expected the two input tensors to have identical shapes. Received input_shape={input_shape}","messagePattern":"Expected the two input tensors to have identical shapes\\. Received input_shape=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashed_crossing.py","lineNumber":121,"sourceCode":"        self.num_bins = num_bins\n        self.output_mode = output_mode\n        self.sparse = sparse\n        self._allow_non_tensor_positional_args = True\n        self._convert_input_args = False\n        self.supports_jit = False\n\n    def compute_output_shape(self, input_shape):\n        if (\n            not len(input_shape) == 2\n            or not isinstance(input_shape[0], tuple)\n            or not isinstance(input_shape[1], tuple)\n        ):\n            raise ValueError(\n                \"Expected as input a list/tuple of 2 tensors. \"\n                f\"Received input_shape={input_shape}\"\n            )\n        if input_shape[0][-1] != input_shape[1][-1]:\n            raise ValueError(\n                \"Expected the two input tensors to have identical shapes. \"\n                f\"Received input_shape={input_shape}\"\n            )\n\n        if not input_shape:\n            if self.output_mode == \"int\":\n                return ()\n            return (self.num_bins,)\n        if self.output_mode == \"int\":\n            return tuple(input_shape[0])\n\n        if self.output_mode == \"one_hot\" and input_shape[0][-1] != 1:\n            return tuple(input_shape[0]) + (self.num_bins,)\n\n        return tuple(input_shape[0])[:-1] + (self.num_bins,)\n\n    def call(self, inputs):\n        from keras.src.backend import tensorflow as tf_backend","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashed_crossing.py#L103-L139","documentation":"HashedCrossing requires its two input tensors to have identical shapes (the last dimension must match). Mismatched shapes make the crossing ill-defined, so compute_output_shape rejects them.","triggerScenarios":"input_shape[0][-1] != input_shape[1][-1], e.g. Input(shape=(1,)) and Input(shape=(2,)) both wired into the crossing layer.","commonSituations":"Two Input layers with different shapes (e.g. (1,) and (2,)); one input reshaped upstream and the other not.","solutions":["Make both inputs the same shape, typically (batch, 1)","Reshape one input upstream: tf.reshape(x, [-1, 1]) or a keras Reshape((1,)) layer","Check Input(shape=...) declarations in Functional models for equality"],"exampleFix":"// before\na = keras.Input(shape=(1,)); b = keras.Input(shape=(2,))\nout = HashedCrossing(100)([a, b])\n// after\na = keras.Input(shape=(1,)); b = keras.Input(shape=(1,))\nout = HashedCrossing(100)([a, b])","handlingStrategy":"validation","validationCode":"assert input_shape[0][-1] == input_shape[1][-1], \"inputs must have identical last dim\"","typeGuard":"def same_last_dim(s):\n    return s[0][-1] == s[1][-1]","tryCatchPattern":"catch ValueError from build/compute_output_shape and reshape both inputs to a common shape before retrying","preventionTips":["Give both inputs to HashedCrossing identical shapes, e.g. (batch, 1) each","Reshape mismatched inputs to (batch, 1) with tf.reshape before feeding the layer"],"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"}