{"record":{"id":"67c28f26f4fabdc7","repo":"keras-team/keras","slug":"layer-hashedcrossing-requires-tensorflow-install","errorCode":null,"errorMessage":"Layer HashedCrossing requires TensorFlow. Install it via `pip install tensorflow`.","messagePattern":"Layer HashedCrossing requires TensorFlow\\. Install it via `pip install tensorflow`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashed_crossing.py","lineNumber":82,"sourceCode":"    >>> layer((feat1, feat2))\n    array([[0., 1., 0., 0., 0.],\n            [0., 0., 0., 0., 1.],\n            [0., 1., 0., 0., 0.],\n            [0., 1., 0., 0., 0.],\n            [0., 0., 0., 1., 0.]], dtype=float32)\n    \"\"\"\n\n    def __init__(\n        self,\n        num_bins,\n        output_mode=\"int\",\n        sparse=False,\n        name=None,\n        dtype=None,\n        **kwargs,\n    ):\n        if not tf.available:\n            raise ImportError(\n                \"Layer HashedCrossing requires TensorFlow. \"\n                \"Install it via `pip install tensorflow`.\"\n            )\n\n        if output_mode == \"int\" and dtype is None:\n            dtype = \"int64\"\n\n        super().__init__(name=name, dtype=dtype)\n        if sparse and backend.backend() != \"tensorflow\":\n            raise ValueError(\n                \"`sparse=True` can only be used with the TensorFlow backend.\"\n            )\n\n        argument_validation.validate_string_arg(\n            output_mode,\n            allowable_strings=(\"int\", \"one_hot\"),\n            caller_name=self.__class__.__name__,\n            arg_name=\"output_mode\",","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashed_crossing.py#L64-L100","documentation":"The HashedCrossing layer relies on TensorFlow ops internally, so Keras raises ImportError at construction time if the tensorflow package is not importable. It cannot run on jax or torch backends regardless of keras config.","triggerScenarios":"Constructing layers.HashedCrossing(...) in a Keras 3 process without tensorflow installed, or with KERAS_BACKEND=jax/torch.","commonSituations":"Running Keras 3 with KERAS_BACKEND=jax or torch and using FeatureSpace crossings or the HashedCrossing layer directly; CI images without TensorFlow installed.","solutions":["pip install tensorflow and switch the Keras backend to tensorflow (KERAS_BACKEND=tensorflow)","Replace HashedCrossing with a backend-agnostic alternative (e.g. combine features and use Hashing) if you must stay on jax/torch","Guard the import and skip crossing features on non-TF setups"],"exampleFix":"// before\nKERAS_BACKEND=jax python train.py  # uses layers.HashedCrossing\n// after\npip install tensorflow  # then\nKERAS_BACKEND=tensorflow python train.py","handlingStrategy":"fallback","validationCode":"from keras.src.backend import tensorflow as tf\nif not tf.available:\n    raise RuntimeError(\"HashedCrossing needs TensorFlow installed\")","typeGuard":"def can_use_hashed_crossing():\n    from keras.src.backend import tensorflow as tf\n    return tf.available","tryCatchPattern":"catch ImportError and either install TensorFlow or replace the crossing with a backend-agnostic preprocessing step","preventionTips":["pip install tensorflow before using HashedCrossing","Avoid features/crossings that need HashedCrossing when running JAX or torch backends"],"tags":["keras","hashed-crossing","tensorflow","import-error"],"backgroundTag":"missing-dependency","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}