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

  1. Cast floats to string: tf.strings.as_string(x)
  2. Cast numeric codes to int: tf.cast(x, tf.int64)
  3. 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

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


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/c1c1bf88f513dcd8. Report an issue: GitHub.