keras-team/keras · error · ValueError
All `HashedCrossing` inputs should have an integer or string
Error message
All `HashedCrossing` inputs should have an integer or string dtype. Received: inputs={inputs} What it means
Crossing works by hashing values, so inputs must be integers or strings. Float tensors (or other dtypes) are rejected because hashing floats is undefined in this layer.
Source
Thrown at keras/src/layers/preprocessing/hashed_crossing.py:226
f"Received: inputs={inputs}"
)
if not all(tuple(x.shape) == first_shape for x in inputs[1:]):
raise ValueError(
"All `HashedCrossing` inputs should have equal shape. "
f"Received: inputs={inputs}"
)
if any(
isinstance(x, (tf.RaggedTensor, tf.SparseTensor)) for x in inputs
):
raise ValueError(
"All `HashedCrossing` inputs should be dense tensors. "
f"Received: inputs={inputs}"
)
if not all(
tf.as_dtype(x.dtype).is_integer or x.dtype == tf.string
for x in inputs
):
raise ValueError(
"All `HashedCrossing` inputs should have an integer or "
f"string dtype. Received: inputs={inputs}"
)
View on GitHub (pinned to 7a34a03db6)
Solutions
- Cast floats to string: tf.strings.as_string(x)
- Cast numeric codes to int: tf.cast(x, tf.int64)
- Keep float features out of crossings or bucketize them (Discretization) into integer bins first
Example fix
// before out = layer([price_float, category_int]) # price is float32 // after price = tf.strings.as_string(price_float) out = layer([price, tf.cast(category_int, tf.int64)])
Defensive patterns
Strategy: validation
Validate before calling
for i, x in enumerate(inputs):
if not (tf.as_dtype(x.dtype).is_integer or x.dtype == tf.string):
inputs[i] = tf.cast(x, tf.int64) # or tf.strings.as_string(x) Type guard
def int_or_string_dtype(inputs):
import tensorflow as tf
return all(tf.as_dtype(x.dtype).is_integer or x.dtype == tf.string for x in inputs) Try / catch
catch ValueError from call() and cast offending inputs (tf.cast(x, tf.int64) or tf.strings.as_string(x)) before retrying
Prevention
- Cast numeric features to a string or integer dtype before crossing
- Keep crossed features as raw strings or integer ids, not floats
When it happens
Trigger: An input whose dtype is neither integer nor tf.string (e.g. float32) reaching the dtype check in _check_input_shape_and_type.
Common situations: Crossing float-encoded numeric features (normalized prices, log transforms); integer ids stored as float64 after pandas/numpy ops; passing embeddings or continuous columns.
Related errors
- `dtype` was passed both positionally and as a keyword argume
- Quantization mode='{mode}' doesn't work well with compute_dt
- Feature '{name}' has `output_mode='one_hot'`. Thus its prepr
- Layer HashedCrossing requires TensorFlow. Install it via `pi
- `sparse=True` can only be used with the TensorFlow backend.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/c1c1bf88f513dcd8.
Report an issue: GitHub.