keras-team/keras · error · ValueError

`sparse=True` can only be used with the TensorFlow backend.

Error message

`sparse=True` can only be used with the TensorFlow backend.

What it means

Error "`sparse=True` can only be used with the TensorFlow backend." thrown in keras-team/keras.

Source

Thrown at keras/src/layers/preprocessing/text_vectorization.py:235

        ngrams=None,
        output_mode="int",
        output_sequence_length=None,
        pad_to_max_tokens=False,
        vocabulary=None,
        idf_weights=None,
        sparse=False,
        ragged=False,
        encoding="utf-8",
        name=None,
        **kwargs,
    ):
        if not tf.available:
            raise ImportError(
                "Layer TextVectorization requires TensorFlow. "
                "Install it via `pip install tensorflow`."
            )
        if sparse and backend.backend() != "tensorflow":
            raise ValueError(
                "`sparse=True` can only be used with the TensorFlow backend."
            )
        if ragged and backend.backend() != "tensorflow":
            raise ValueError(
                "`ragged=True` can only be used with the TensorFlow backend."
            )

        # 'standardize' must be one of
        # (None, "lower_and_strip_punctuation", "lower", "strip_punctuation",
        # callable)
        argument_validation.validate_string_arg(
            standardize,
            allowable_strings=(
                "lower_and_strip_punctuation",
                "lower",
                "strip_punctuation",
            ),
            caller_name=self.__class__.__name__,

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/preprocessing/text_vectorization.py:235 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/6111e206c7456583. Report an issue: GitHub.