keras-team/keras · error · ValueError

Multiple target dimensions are not supported. Expected…

Error message

Multiple target dimensions are not supported. Expected: None, int, (int, int), Provided: {axes} 

What it means

Axes normalization in batch_dot: after ints are expanded and None is defaulted, any axis entry that is itself a list/tuple means a per-batch-element target dimension was requested, which this implementation does not support, so the generic guard rejects it.

Solutions

  1. Pass axes as a single int or a 2-element list/tuple of ints, e.g. axes=2 or axes=(2, 3)
  2. If you need different axes per sample, split the batch and loop, calling batch_dot once per group with scalar axes
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    if x_batch_size is not None and y_batch_size is not None:
        if x_batch_size != y_batch_size:
            raise ValueError(
                f"Cannot do batch_dot on inputs "
                f"with different batch sizes. "
                f"Received inputs with shapes "
                f"{x_shape} and {y_shape}."
            )
    if isinstance(axes, int):
        axes = [axes, axes]

    if axes is None:
        if y_ndim == 2:
            axes = [x_ndim - 1, y_ndim - 1]
        else:
            axes = [x_ndim - 1, y_ndim - 2]

    if any(isinstance(a, (list, tuple)) for a in axes):
        raise ValueError(
            f"Multiple target dimensions are not supported. "
            f"Expected: None, int, (int, int), "
            f"Provided: {axes} "
        )

    # if tuple, convert to list.
    axes = list(axes)

    # convert negative indices.
    if axes[0] < 0:
        axes[0] += x_ndim
    if axes[1] < 0:
        axes[1] += y_ndim

    # sanity checks
    if 0 in axes:
        raise ValueError(
            "Cannot perform batch_dot over axis 0. "

View on GitHub (pinned to 7a34a03db6)