This function receives as input a string of text and returns a
list of encoded integers each corresponding to a word (or token)
in the given input string.
Args
input_text
Input text (string).
n
int. Size of vocabulary.
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
Returns
List of integers in [1, n]. Each integer encodes a word
(unicity non-guaranteed).
[null,null,["Last updated 2024-01-23 UTC."],[],[],null,["# tf.keras.preprocessing.text.one_hot\n\n|----------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/text.py#L84-L132) |\n\nOne-hot encodes a text into a list of word indexes of size `n`. \n\n tf.keras.preprocessing.text.one_hot(\n input_text,\n n,\n filters='!\"#$%&()*+,-./:;\u003c=\u003e?@[\\\\]^_`{|}~\\t\\n',\n lower=True,\n split=' ',\n analyzer=None\n )\n\n| **Deprecated:** `tf.keras.text.preprocessing.one_hot` does not operate on tensors and is not recommended for new code. Prefer [`tf.keras.layers.Hashing`](../../../../tf/keras/layers/Hashing) with `output_mode='one_hot'` which provides equivalent functionality through a layer which accepts [`tf.Tensor`](../../../../tf/Tensor) input. See the [preprocessing layer guide](https://www.tensorflow.org/guide/keras/preprocessing_layers) for an overview of preprocessing layers.\n\nThis function receives as input a string of text and returns a\nlist of encoded integers each corresponding to a word (or token)\nin the given input string.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_text` | Input text (string). |\n| `n` | int. Size of vocabulary. |\n| `filters` | list (or concatenation) of characters to filter out, such as punctuation. Default: ``'!\"#$%&()*+,-./:;\u003c=\u003e?@[\\]^_`{|}~\\t\\n``, includes basic punctuation, tabs, and newlines. |\n| `lower` | boolean. Whether to set the text to lowercase. |\n| `split` | str. Separator for word splitting. |\n| `analyzer` | function. Custom analyzer to split the text |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| List of integers in `[1, n]`. Each integer encodes a word (unicity non-guaranteed). ||\n\n\u003cbr /\u003e"]]