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/string_lookup.py:325
oov_token="[UNK]",
vocabulary=None,
idf_weights=None,
invert=False,
output_mode="int",
pad_to_max_tokens=False,
sparse=False,
encoding="utf-8",
name=None,
salt=None,
**kwargs,
):
if not tf.available:
raise ImportError(
"Layer StringLookup 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."
)
self.encoding = encoding
super().__init__(
max_tokens=max_tokens,
num_oov_indices=num_oov_indices,
mask_token=mask_token,
oov_token=oov_token,
vocabulary=vocabulary,
idf_weights=idf_weights,
invert=invert,
output_mode=output_mode,
pad_to_max_tokens=pad_to_max_tokens,
sparse=sparse,
name=name,
salt=salt,
vocabulary_dtype="string",
**kwargs,View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/string_lookup.py:325 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/817e1aa3681d6ae0.
Report an issue: GitHub.