{"record":{"id":"9ff6c146cad21254","repo":"keras-team/keras","slug":"layer-hashing-requires-tensorflow-install-it-via","errorCode":null,"errorMessage":"Layer Hashing requires TensorFlow. Install it via `pip install tensorflow`.","messagePattern":"Layer Hashing requires TensorFlow\\. Install it via `pip install tensorflow`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/hashing.py","lineNumber":147,"sourceCode":"    Output shape:\n        An `int32` tensor of shape `(batch_size, ...)`.\n\n    Reference:\n\n    - [SipHash with salt](https://www.131002.net/siphash/siphash.pdf)\n    \"\"\"\n\n    def __init__(\n        self,\n        num_bins,\n        mask_value=None,\n        salt=None,\n        output_mode=\"int\",\n        sparse=False,\n        **kwargs,\n    ):\n        if not tf.available:\n            raise ImportError(\n                \"Layer Hashing requires TensorFlow. \"\n                \"Install it via `pip install tensorflow`.\"\n            )\n\n        # By default, output int32 when output_mode='int' and floats otherwise.\n        if \"dtype\" not in kwargs or kwargs[\"dtype\"] is None:\n            kwargs[\"dtype\"] = (\n                \"int64\" if output_mode == \"int\" else backend.floatx()\n            )\n\n        super().__init__(**kwargs)\n\n        if num_bins is None or num_bins <= 0:\n            raise ValueError(\n                \"The `num_bins` for `Hashing` cannot be `None` or \"\n                f\"non-positive values. Received: num_bins={num_bins}.\"\n            )\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/hashing.py#L129-L165","documentation":"The Hashing preprocessing layer is implemented on top of TensorFlow ops (SipHash). This ImportError is raised at layer construction when TensorFlow is not importable in the current environment, regardless of which Keras backend is active.","triggerScenarios":"Constructing layers.Hashing(...) in a Keras 3 process without tensorflow installed, or with KERAS_BACKEND=jax/torch.","commonSituations":"Keras 3 with jax or torch backend using FeatureSpace integer_hashed/string_hashed features or layers.Hashing; slim environments where tensorflow was never installed.","solutions":["pip install tensorflow and run with KERAS_BACKEND=tensorflow","On other backends, hash features in the input pipeline (precompute) or use a different feature spec","Guard feature specs so hashed features are only created when TF is present"],"exampleFix":"// before\nKERAS_BACKEND=jax python train.py  # uses layers.Hashing\n// after\npip install tensorflow\nKERAS_BACKEND=tensorflow python train.py","handlingStrategy":"fallback","validationCode":"from keras.src.backend import tensorflow as tf\nif not tf.available:\n    raise RuntimeError(\"Hashing layer needs TensorFlow installed\")","typeGuard":"def can_use_hashing():\n    from keras.src.backend import tensorflow as tf\n    return tf.available","tryCatchPattern":"catch ImportError and either install TensorFlow or precompute hashes in the input pipeline","preventionTips":["pip install tensorflow before using the Hashing layer","On JAX/torch backends, hash features upstream instead of using this layer"],"tags":["keras","hashing","tensorflow","import-error"],"backgroundTag":"missing-dependency","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}