tf.keras.preprocessing.text.text_to_word_sequence
Stay organized with collections
Save and categorize content based on your preferences.
Converts a text to a sequence of words (or tokens).
tf.keras.preprocessing.text.text_to_word_sequence(
input_text,
filters='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~\t\n',
lower=True,
split=' '
)
This function transforms a string of text into a list of words
while ignoring filters
which include punctuations by default.
sample_text = 'This is a sample sentence.'
tf.keras.preprocessing.text.text_to_word_sequence(sample_text)
['this', 'is', 'a', 'sample', 'sentence']
Args |
input_text
|
Input text (string).
|
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 convert the input to lowercase.
|
split
|
str. Separator for word splitting.
|
Returns |
A list of words (or tokens).
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-01-23 UTC.
[null,null,["Last updated 2024-01-23 UTC."],[],[],null,["# tf.keras.preprocessing.text.text_to_word_sequence\n\n|---------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/text.py#L39-L81) |\n\nConverts a text to a sequence of words (or tokens). \n\n tf.keras.preprocessing.text.text_to_word_sequence(\n input_text,\n filters='!\"#$%&()*+,-./:;\u003c=\u003e?@[\\\\]^_`{|}~\\t\\n',\n lower=True,\n split=' '\n )\n\n| **Deprecated:** [`tf.keras.preprocessing.text.text_to_word_sequence`](../../../../tf/keras/preprocessing/text/text_to_word_sequence) does not operate on tensors and is not recommended for new code. Prefer [`tf.strings.regex_replace`](../../../../tf/strings/regex_replace) and [`tf.strings.split`](../../../../tf/strings/split) which provide equivalent functionality and accept [`tf.Tensor`](../../../../tf/Tensor) input. For an overview of text handling in Tensorflow, see the [text loading tutorial](https://www.tensorflow.org/tutorials/load_data/text).\n\nThis function transforms a string of text into a list of words\nwhile ignoring `filters` which include punctuations by default. \n\n sample_text = 'This is a sample sentence.'\n tf.keras.preprocessing.text.text_to_word_sequence(sample_text)\n ['this', 'is', 'a', 'sample', 'sentence']\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_text` | Input text (string). |\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 convert the input to lowercase. |\n| `split` | str. Separator for word splitting. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A list of words (or tokens). ||\n\n\u003cbr /\u003e"]]