A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://keras.io/api/layers/preprocessing_layers/categorical/hashing below:

Hashing layer

Hashing layer

[source]

Hashing class
keras.layers.Hashing(
    num_bins, mask_value=None, salt=None, output_mode="int", sparse=False, **kwargs
)

A preprocessing layer which hashes and bins categorical features.

This layer transforms categorical inputs to hashed output. It element-wise converts a ints or strings to ints in a fixed range. The stable hash function uses tensorflow::ops::Fingerprint to produce the same output consistently across all platforms.

This layer uses FarmHash64 by default, which provides a consistent hashed output across different platforms and is stable across invocations, regardless of device and context, by mixing the input bits thoroughly.

If you want to obfuscate the hashed output, you can also pass a random salt argument in the constructor. In that case, the layer will use the SipHash64 hash function, with the salt value serving as additional input to the hash function.

Note: This layer internally uses TensorFlow. It cannot be used as part of the compiled computation graph of a model with any backend other than TensorFlow. It can however be used with any backend when running eagerly. It can also always be used as part of an input preprocessing pipeline with any backend (outside the model itself), which is how we recommend to use this layer.

Note: This layer is safe to use inside a tf.data pipeline (independently of which backend you're using).

Example (FarmHash64)

>>> layer = keras.layers.Hashing(num_bins=3)
>>> inp = [['A'], ['B'], ['C'], ['D'], ['E']]
>>> layer(inp)
array([[1],
        [0],
        [1],
        [1],
        [2]])>

Example (FarmHash64) with a mask value

>>> layer = keras.layers.Hashing(num_bins=3, mask_value='')
>>> inp = [['A'], ['B'], [''], ['C'], ['D']]
>>> layer(inp)
array([[1],
        [1],
        [0],
        [2],
        [2]])

Example (SipHash64)

>>> layer = keras.layers.Hashing(num_bins=3, salt=[133, 137])
>>> inp = [['A'], ['B'], ['C'], ['D'], ['E']]
>>> layer(inp)
array([[1],
        [2],
        [1],
        [0],
        [2]])

Example (Siphash64 with a single integer, same as salt=[133, 133])

>>> layer = keras.layers.Hashing(num_bins=3, salt=133)
>>> inp = [['A'], ['B'], ['C'], ['D'], ['E']]
>>> layer(inp)
array([[0],
        [0],
        [2],
        [1],
        [0]])

Arguments

Input shape

A single string, a list of strings, or an int32 or int64 tensor of shape (batch_size, ...,).

Output shape

An int32 tensor of shape (batch_size, ...).

Reference


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4