keras-team/keras · error · ValueError
You need to call `.adapt(dataset)` on the FeatureSpace befor
Error message
You need to call `.adapt(dataset)` on the FeatureSpace before you can start using it.
What it means
FeatureSpace must be adapted to data before use whenever it contains adaptable preprocessors (lookup/vocabulary layers). adapt() computes vocabularies; without it the layer cannot translate raw values to indices and refuses to run.
Source
Thrown at keras/src/layers/preprocessing/feature_space.py:741
f"has not been encoded (it has dtype {dtype}). "
"Consider using `output_mode='dict'`."
)
features_to_concat.append(feature)
else:
output_dict[name] = feature
if self.output_mode == "concat":
self.concat = TFDConcat(axis=-1)
return self.concat(features_to_concat)
else:
return output_dict
def _check_if_adapted(self):
if not self._is_adapted:
if not self._list_adaptable_preprocessors():
self._is_adapted = True
else:
raise ValueError(
"You need to call `.adapt(dataset)` on the FeatureSpace "
"before you can start using it."
)
def _check_if_built(self):
if not self._sublayers_built:
self._check_if_adapted()
# Finishes building
self.get_encoded_features()
self._sublayers_built = True
def _convert_input(self, x):
if not isinstance(x, (tf.Tensor, tf.SparseTensor, tf.RaggedTensor)):
if not isinstance(x, (list, tuple, int, float)):
x = backend.convert_to_numpy(x)
x = tf.convert_to_tensor(x)
return x
View on GitHub (pinned to 7a34a03db6)
Solutions
- Call fs.adapt(dataset) on your raw (unencoded) training data before get_encoded_features()/__call__
- If there are truly no adaptable features, ensure none of the feature specs create lookup layers
- Re-adapt after changing feature specs
Example fix
// before fs = FeatureSpace(features) inputs = fs.get_encoded_features() # ValueError // after fs = FeatureSpace(features) fs.adapt(train_ds) inputs = fs.get_encoded_features()
Defensive patterns
Strategy: validation
Validate before calling
if fs._list_adaptable_preprocessors() and not fs._is_adapted:
fs.adapt(raw_train_data) # adapt before use Type guard
def is_adapted(fs):
return fs._is_adapted or not fs._list_adaptable_preprocessors() Try / catch
catch ValueError around model/FeatureSpace usage and call fs.adapt(unlabeled_data) before retrying
Prevention
- Always call fs.adapt(train_ds) once after construction, before training or inference
- Save/load via fs.save()/FeatureSpace.load to preserve adapted state across restarts
When it happens
Trigger: Calling fs.get_encoded_features(), fs(data), or _check_if_built paths before any fs.adapt(dataset) call, while the feature specs include vocabulary/hash-based preprocessors.
Common situations: Building a model that calls FeatureSpace before adapt(); loading a FeatureSpace config without its adapted state; skipping adapt because the data 'already looks fine'.
Related errors
- `adapt()` can only be called on a tf.data.Dataset or a dict
- Feature '{name}' has `output_mode='one_hot'`. Thus its prepr
- Feature '{name}' has `output_mode='one_hot'`. However it isn
- Cannot concatenate features because feature '{name}' has not
- 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/ad023036bdb2e2d7.
Report an issue: GitHub.