keras-team/keras · error · ValueError
`count_weights` is not used when `output_mode` is not…
Error message
`count_weights` is not used when `output_mode` is not `'count'`. Received `count_weights={count_weights}`. What it means
CategoryEncoding.call received count_weights while the layer's output_mode is not 'count'. Weights only apply when summing occurrence counts; in 'one_hot' and 'multi_hot' modes they have no defined meaning, so passing them is treated as a likely caller mistake and rejected.
Solutions
- Drop the count_weights argument when output_mode is 'one_hot' or 'multi_hot'
- Set output_mode='count' if you actually need weighted counts
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/category_encoding.py:159 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/6d5965cce4e9406b.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/category_encoding.py:159
def compute_output_spec(self, inputs, count_weights=None):
output_shape = self.compute_output_shape(inputs.shape)
return KerasTensor(
output_shape, dtype=self.compute_dtype, sparse=self.sparse
)
def get_config(self):
config = {
"num_tokens": self.num_tokens,
"output_mode": self.output_mode,
"sparse": self.sparse,
}
base_config = super().get_config()
return {**base_config, **config}
def call(self, inputs, count_weights=None):
if count_weights is not None:
if self.output_mode != "count":
raise ValueError(
"`count_weights` is not used when `output_mode` is not "
f"`'count'`. Received `count_weights={count_weights}`."
)
count_weights = self.backend.convert_to_tensor(
count_weights, dtype=self.compute_dtype
)
outputs = self._encode(inputs, count_weights)
return backend_utils.convert_tf_tensor(outputs)
View on GitHub (pinned to 7a34a03db6)