keras-team/keras · error · ValueError

Bias dimension '{char}' was requested, but is not part of th

Error message

Bias dimension '{char}' was requested, but is not part of the output spec '{output_spec}'

What it means

EinsumDense's bias_axes argument names output dimensions that should receive a bias. Each letter in bias_axes must be part of the output spec of the equation; otherwise the bias vector's shape is undefined and _analyze_split_string raises this error.

Source

Thrown at keras/src/layers/core/einsum_dense.py:1878

            input_axes.append(i)
        else:
            raise ValueError(
                f"Weight dimension '{dim}' did not have a match in either "
                f"the input spec '{input_spec}' or the output "
                f"spec '{output_spec}'. For this layer, the weight must "
                "be fully specified."
            )

    if bias_axes is not None:
        num_left_elided = elided if left_elided else 0
        idx_map = {
            char: output_shape[i + num_left_elided]
            for i, char in enumerate(output_spec)
        }

        for char in bias_axes:
            if char not in output_spec:
                raise ValueError(
                    f"Bias dimension '{char}' was requested, but is not part "
                    f"of the output spec '{output_spec}'"
                )

        first_bias_location = min(
            [output_spec.find(char) for char in bias_axes]
        )
        bias_output_spec = output_spec[first_bias_location:]

        bias_shape = [
            idx_map[char] if char in bias_axes else 1
            for char in bias_output_spec
        ]

        if not left_elided:
            for _ in range(elided):
                bias_shape.append(1)
    else:

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Set bias_axes to letters present in the output spec only (commonly the last output letter, e.g. 'c' in 'ab,bc->ac')
  2. Use bias_axes=None to disable bias
  3. Update bias_axes whenever you rename equation letters

Example fix

# before
layer = EinsumDense('ab,bc->ac', output_shape=(None, 5), bias_axes='b')
# after
layer = EinsumDense('ab,bc->ac', output_shape=(None, 5), bias_axes='c')
Defensive patterns

Strategy: validation

Validate before calling

def bias_axes_valid(eq, bias_axes):
    out = eq.split('->')[1]
    return bias_axes is None or all(c in out for c in bias_axes)

Type guard

def is_valid_bias_axes(eq, bias_axes):
    return bias_axes is None or (isinstance(bias_axes, str) and bias_axes_valid(eq, bias_axes))

Prevention

When it happens

Trigger: Passing bias_axes containing a letter not in the equation's output, e.g. EinsumDense('ab,bc->ac', ..., bias_axes='b'), or bias_axes with a letter that exists only in the input/weight operands.

Common situations: Copy-pasting a Dense-style bias_axes='b' default into a custom equation where 'b' is not an output letter; renaming equation letters without updating bias_axes; assuming bias_axes refers to input dims.

Related errors


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