|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/text.py#L135-L191) |

Converts a text to a sequence of indexes in a fixed-size hashing space.

    tf.keras.preprocessing.text.hashing_trick(
        text,
        n,
        hash_function=None,
        filters='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~\t\n',
        lower=True,
        split=' ',
        analyzer=None
    )

> [!WARNING]
> **Deprecated:** `tf.keras.text.preprocessing.hashing_trick` does not operate on tensors and is not recommended for new code. Prefer [`tf.keras.layers.Hashing`](https://www.tensorflow.org/versions/r2.15/api_docs/python/tf/keras/layers/Hashing) which provides equivalent functionality through a layer which accepts [`tf.Tensor`](https://www.tensorflow.org/versions/r2.15/api_docs/python/tf/Tensor) input. See the [preprocessing layer guide](https://www.tensorflow.org/guide/keras/preprocessing_layers) for an overview of preprocessing layers.

<br />

<br />

<br />

| ## Args ||
|---|---|
| [`text`](https://www.tensorflow.org/text/api_docs/python/text) | Input text (string). |
| `n` | Dimension of the hashing space. |
| `hash_function` | When `None` uses a python `hash` function. Can be 'md5' or any function that takes in input a string and returns a int. Note that 'hash' is not a stable hashing function, so it is not consistent across different runs, while 'md5' is a stable hashing function. Defaults to `None`. |
| `filters` | list (or concatenation) of characters to filter out, such as punctuation. Default: ``!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~\\t\\n``, includes basic punctuation, tabs, and newlines. |
| `lower` | boolean. Whether to set the text to lowercase. |
| `split` | str. Separator for word splitting. |
| `analyzer` | function. Custom analyzer to split the text |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A list of integer word indices (unicity non-guaranteed). `0` is a reserved index that won't be assigned to any word. Two or more words may be assigned to the same index, due to possible collisions by the hashing function. The [probability](https://en.wikipedia.org/wiki/Birthday_problem#Probability_table) of a collision is in relation to the dimension of the hashing space and the number of distinct objects. ||

<br />