keras-team/keras · error · ValueError
Unsupported value `sparse=True` with numpy backend
Error message
Unsupported value `sparse=True` with numpy backend
What it means
Error "Unsupported value `sparse=True` with numpy backend" thrown in keras-team/keras.
Source
Thrown at keras/src/backend/numpy/nn.py:822
include_batch_and_channels=False,
)
return np.array(
jax.lax.conv_transpose(
inputs,
kernel if is_tensor(kernel) else kernel.numpy(),
strides,
padding=padding_values,
rhs_dilation=dilation_rate,
dimension_numbers=dimension_numbers,
transpose_kernel=True,
)
)
def one_hot(x, num_classes, axis=-1, dtype=None, sparse=False):
if sparse:
raise ValueError("Unsupported value `sparse=True` with numpy backend")
if dtype is None:
dtype = "float32"
x = convert_to_tensor(x)
input_shape = x.shape
x = x.reshape(-1)
if not num_classes:
num_classes = np.max(x) + 1
batch_size = x.shape[0]
categorical = np.zeros((batch_size, num_classes), dtype=dtype)
valid_indices = x >= 0
categorical[np.arange(batch_size)[valid_indices], x[valid_indices]] = 1
# First, reshape the array with the extra dimension at the end
output_shape = input_shape + (num_classes,)
categorical = np.reshape(categorical, output_shape)
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/numpy/nn.py:822 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/372a471e9f2aa870.
Report an issue: GitHub.