keras-team/keras · error · ValueError

A `Dot` layer should be called on a list of 2 inputs…

Error message

A `Dot` layer should be called on a list of 2 inputs. Received: input_shape={input_shape}

What it means

Shape validation in Dot.build: this layer is a binary merge layer and expects input_shape to be a list/tuple of exactly two shapes; passing a single shape or a list of 1/3+ shapes fails the isinstance and length conditions at this guard.

Solutions

  1. Call the layer on a list of two tensors: layer([x1, x2])
  2. For three or more inputs, chain Dot layers or use keras.ops.concatenate/stack before a single Dot
  3. If only one input is available, split it (e.g. by slicing feature dims) into two tensors first
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/layers/merging/dot.py:271 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at keras/src/layers/merging/dot.py:271

                    f"two elements. Received: axes={axes}"
                )
            if not isinstance(axes[0], int) or not isinstance(axes[1], int):
                raise ValueError(
                    f"Invalid format for argument `axes`: list elements should "
                    f"be integers. Received: axes={axes}"
                )
        self.axes = axes
        self.normalize = normalize
        self.supports_masking = True
        self._reshape_required = False

    def build(self, input_shape):
        # Used purely for shape validation.
        if (
            not isinstance(input_shape[0], (tuple, list))
            or len(input_shape) != 2
        ):
            raise ValueError(
                f"A `Dot` layer should be called on a list of 2 inputs. "
                f"Received: input_shape={input_shape}"
            )
        shape1 = input_shape[0]
        shape2 = input_shape[1]
        if shape1 is None or shape2 is None:
            return
        if isinstance(self.axes, int):
            if self.axes < 0:
                axes = [self.axes % len(shape1), self.axes % len(shape2)]
            else:
                axes = [self.axes] * 2
        else:
            axes = self.axes
        if shape1[axes[0]] != shape2[axes[1]]:
            raise ValueError(
                f"Incompatible input shapes: "
                f"axis values {shape1[axes[0]]} (at axis {axes[0]}) != "

View on GitHub (pinned to 7a34a03db6)