keras-team/keras · error · ValueError

Cannot apply softmax to a tensor that is 1D. Received input:

Error message

Cannot apply softmax to a tensor that is 1D. Received input: {x}

What it means

Error "Cannot apply softmax to a tensor that is 1D. Received input: {x}" thrown in keras-team/keras.

Source

Thrown at keras/src/legacy/backend.py:1910


@keras_export("keras._legacy.backend.sign")
def sign(x):
    """DEPRECATED."""
    return tf.sign(x)


@keras_export("keras._legacy.backend.sin")
def sin(x):
    """DEPRECATED."""
    return tf.sin(x)


@keras_export("keras._legacy.backend.softmax")
def softmax(x, axis=-1):
    """DEPRECATED."""
    if x.shape.rank <= 1:
        raise ValueError(
            f"Cannot apply softmax to a tensor that is 1D. Received input: {x}"
        )

    if isinstance(axis, int):
        output = tf.nn.softmax(x, axis=axis)
    else:
        # nn.softmax does not support tuple axis.
        numerator = tf.exp(x - tf.reduce_max(x, axis=axis, keepdims=True))
        denominator = tf.reduce_sum(numerator, axis=axis, keepdims=True)
        output = numerator / denominator

    # Cache the logits to use for crossentropy loss.
    output._keras_logits = x
    return output


@keras_export("keras._legacy.backend.softplus")
def softplus(x):

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/legacy/backend.py:1910 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/e93cb3c58742d800. Report an issue: GitHub.