keras-team/keras · error · ValueError
Feature '{name}' has `output_mode='one_hot'`. However it isn
Error message
Feature '{name}' has `output_mode='one_hot'`. However it isn't a standard feature and the dimensionality of its output space is not known, thus it cannot be one-hot encoded. Try using `output_mode='int'`. What it means
To one-hot encode a feature, FeatureSpace must know the output dimensionality (cardinality). It can infer num_bins only from standard preprocessors (IntegerHashed/StringHashed/CategoryCrossing/Hashing, etc.). A custom or non-standard preprocessor gives no cardinality, so one_hot is impossible.
Source
Thrown at keras/src/layers/preprocessing/feature_space.py:704
f"Feature '{name}' has `output_mode='one_hot'`. "
"Thus its preprocessor should return an integer dtype. "
f"Instead it returns a {dtype} dtype."
)
if isinstance(
preprocessor, (layers.IntegerLookup, layers.StringLookup)
):
cardinality = preprocessor.vocabulary_size()
elif isinstance(preprocessor, layers.CategoryEncoding):
cardinality = preprocessor.num_tokens
elif isinstance(preprocessor, layers.Discretization):
cardinality = preprocessor.num_bins
elif isinstance(
preprocessor, (layers.HashedCrossing, layers.Hashing)
):
cardinality = preprocessor.num_bins
else:
raise ValueError(
f"Feature '{name}' has `output_mode='one_hot'`. "
"However it isn't a standard feature and the "
"dimensionality of its output space is not known, "
"thus it cannot be one-hot encoded. "
"Try using `output_mode='int'`."
)
if cardinality is not None:
encoder = layers.CategoryEncoding(
num_tokens=cardinality, output_mode="multi_hot"
)
self.one_hot_encoders[name] = encoder
feature = encoder(feature)
if self.output_mode == "concat":
dtype = feature.dtype
if dtype.startswith("int") or dtype == "string":
raise ValueError(
f"Cannot concatenate features because feature '{name}' "View on GitHub (pinned to 7a34a03db6)
Solutions
- Switch the feature (or the whole FeatureSpace) to output_mode='int'
- If you need one-hot, map the feature to a standard preprocessor that exposes num_bins (Hashing/HashedCrossing/CategoryEncoding)
- Add a CategoryEncoding(num_tokens=known_cardinality) layer downstream to one-hot the int output yourself
Example fix
// before
fs = FeatureSpace(features={"cross": FeatureSpace.cross(feature_names=("a","b"), output_mode="one_hot")}, output_mode="concat")
// after
fs = FeatureSpace(features={"cross": FeatureSpace.cross(feature_names=("a","b"), output_mode="int")}, output_mode="int") Defensive patterns
Strategy: validation
Validate before calling
p = fs.preprocessors.get(name) or fs.crossers.get(name)
if not hasattr(p, "num_bins"):
# cannot infer cardinality; use output_mode='int' Type guard
def one_hot_supported(p):
return hasattr(p, "num_bins") Try / catch
catch ValueError from get_encoded_features/__call__, then switch the FeatureSpace (or crossing) output_mode to 'int'
Prevention
- Use output_mode='int' for custom or crossing features whose output cardinality is unknown
- Restrict one_hot to features backed by lookup/hashing layers that expose num_bins
When it happens
Trigger: FeatureSpace(output_mode='one_hot') with a custom feature spec (e.g. FeatureSpace.feature(preprocessor=CustomLayer)) or a non-hashing crossing preprocessor, where the layer has no num_bins attribute.
Common situations: Custom crossing implementations, features built from Lambda or non-standard preprocessing layers, or crossing features without an underlying hashing/lookup layer.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Feature '{name}' has `output_mode='one_hot'`. Thus its prepr
- `adapt()` can only be called on a tf.data.Dataset or a dict
- Cannot concatenate features because feature '{name}' has not
- You need to call `.adapt(dataset)` on the FeatureSpace befor
- A FeatureSpace can only be called with a dict. Received: dat
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/280c3460cdb7056c.
Report an issue: GitHub.