keras-team/keras · error · TypeError

Invalid type for argument `axes`: it should be a list or an…

Error message

Invalid type for argument `axes`: it should be a list or an int. Received: axes={axes}

What it means

Input validation in Dot.__init__: the `axes` constructor argument must be an int or a list/tuple; anything else (string, dict, None, float) is a type error at this guard because no axis interpretation exists for it.

Solutions

  1. Pass axes as an int, e.g. axes=-1, or a 2-element list/tuple like axes=[2, 2]
  2. If axes comes from a config file, cast it to int or list before constructing the layer
  3. Leave axes out entirely when defaulting to int(-1) is acceptable
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at keras/src/layers/merging/dot.py:246 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/0871b744fd2ef668. Report an issue: GitHub.

Appendix: source

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

            corresponding to the desired axis from the first input and the
            desired axis from the second input, respectively. Note that the
            size of the two selected axes must match, and that
            axis `0` (the batch axis) cannot be included.
        normalize: Whether to L2-normalize samples along the dot product axis
            before taking the dot product. If set to `True`, then
            the output of the dot product is the cosine proximity
            between the two samples.
        **kwargs: Standard layer keyword arguments.

    Returns:
        A tensor, the dot product of the samples from the inputs.
    """

    def __init__(self, axes, normalize=False, **kwargs):
        super().__init__(**kwargs)
        if not isinstance(axes, int):
            if not isinstance(axes, (list, tuple)):
                raise TypeError(
                    f"Invalid type for argument `axes`: it should be "
                    f"a list or an int. Received: axes={axes}"
                )
            if len(axes) != 2:
                raise ValueError(
                    f"Invalid format for argument `axes`: it should contain "
                    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

View on GitHub (pinned to 7a34a03db6)