keras-team/keras · error · ValueError

Argument `num_segments` cannot be set when sorted is True wh

Error message

Argument `num_segments` cannot be set when sorted is True when using the tensorflow backend.Received: num_segments={num_segments}, sorted={sorted}.

What it means

Error "Argument `num_segments` cannot be set when sorted is True when using the tensorflow backend.Received: num_segments={num_segments}, sorted={sorted}." thrown in keras-team/keras.

Source

Thrown at keras/src/backend/tensorflow/math.py:12

import tensorflow as tf

from keras.src.backend import standardize_dtype
from keras.src.backend.common import dtypes
from keras.src.backend.tensorflow.core import cast
from keras.src.backend.tensorflow.core import convert_to_tensor


def segment_sum(data, segment_ids, num_segments=None, sorted=False):
    if sorted:
        if num_segments is not None:
            raise ValueError(
                "Argument `num_segments` cannot be set when sorted is True "
                "when using the tensorflow backend."
                f"Received: num_segments={num_segments}, sorted={sorted}."
            )
        return tf.math.segment_sum(data, segment_ids)
    else:
        if num_segments is None:
            unique_segment_ids, _ = tf.unique(segment_ids)
            num_segments = tf.shape(unique_segment_ids)[0]
        return tf.math.unsorted_segment_sum(data, segment_ids, num_segments)


def segment_max(data, segment_ids, num_segments=None, sorted=False):
    if sorted:
        if num_segments is not None:
            raise ValueError(
                "Argument `num_segments` cannot be set when sorted is True "
                "when using the tensorflow backend."

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/tensorflow/math.py:12 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/3a787e4216387ccc. Report an issue: GitHub.