tf.compat.v1.strings.split
Stay organized with collections
Save and categorize content based on your preferences.
Split elements of input
based on sep
.
tf.compat.v1.strings.split(
input=None,
sep=None,
maxsplit=-1,
result_type='SparseTensor',
source=None,
name=None
)
Let N be the size of input
(typically N will be the batch size). Split each
element of input
based on sep
and return a SparseTensor
or
RaggedTensor
containing the split tokens. Empty tokens are ignored.
Examples:
print(tf.compat.v1.strings.split(['hello world', 'a b c']))
SparseTensor(indices=tf.Tensor( [[0 0] [0 1] [1 0] [1 1] [1 2]], ...),
values=tf.Tensor([b'hello' b'world' b'a' b'b' b'c'], ...),
dense_shape=tf.Tensor([2 3], shape=(2,), dtype=int64))
print(tf.compat.v1.strings.split(['hello world', 'a b c'],
result_type="RaggedTensor"))
<tf.RaggedTensor [[b'hello', b'world'], [b'a', b'b', b'c']]>
If sep
is given, consecutive delimiters are not grouped together and are
deemed to delimit empty strings. For example, input
of "1<>2<><>3"
and
sep
of "<>"
returns ["1", "2", "", "3"]
. If sep
is None or an empty
string, consecutive whitespace are regarded as a single separator, and the
result will contain no empty strings at the start or end if the string has
leading or trailing whitespace.
Note that the above mentioned behavior matches python's str.split.
Args |
input
|
A string Tensor of rank N , the strings to split. If
rank(input) is not known statically, then it is assumed to be 1 .
|
sep
|
0-D string Tensor , the delimiter character.
|
maxsplit
|
An int . If maxsplit > 0 , limit of the split of the result.
|
result_type
|
The tensor type for the result: one of "RaggedTensor" or
"SparseTensor" .
|
source
|
alias for "input" argument.
|
name
|
A name for the operation (optional).
|
Raises |
ValueError
|
If sep is not a string.
|
Returns |
A SparseTensor or RaggedTensor of rank N+1 , the strings split
according to the delimiter.
|
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-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.strings.split\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/ragged/ragged_string_ops.py#L593-L657) |\n\nSplit elements of `input` based on `sep`. \n\n tf.compat.v1.strings.split(\n input=None,\n sep=None,\n maxsplit=-1,\n result_type='SparseTensor',\n source=None,\n name=None\n )\n\nLet N be the size of `input` (typically N will be the batch size). Split each\nelement of `input` based on `sep` and return a `SparseTensor` or\n`RaggedTensor` containing the split tokens. Empty tokens are ignored.\n\n#### Examples:\n\n print(tf.compat.v1.strings.split(['hello world', 'a b c']))\n SparseTensor(indices=tf.Tensor( [[0 0] [0 1] [1 0] [1 1] [1 2]], ...),\n values=tf.Tensor([b'hello' b'world' b'a' b'b' b'c'], ...),\n dense_shape=tf.Tensor([2 3], shape=(2,), dtype=int64))\n\n print(tf.compat.v1.strings.split(['hello world', 'a b c'],\n result_type=\"RaggedTensor\"))\n \u003ctf.RaggedTensor [[b'hello', b'world'], [b'a', b'b', b'c']]\u003e\n\nIf `sep` is given, consecutive delimiters are not grouped together and are\ndeemed to delimit empty strings. For example, `input` of `\"1\u003c\u003e2\u003c\u003e\u003c\u003e3\"` and\n`sep` of `\"\u003c\u003e\"` returns `[\"1\", \"2\", \"\", \"3\"]`. If `sep` is None or an empty\nstring, consecutive whitespace are regarded as a single separator, and the\nresult will contain no empty strings at the start or end if the string has\nleading or trailing whitespace.\n\nNote that the above mentioned behavior matches python's str.split.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|------------------------------------------------------------------------------------------------------------------------------|\n| `input` | A string `Tensor` of rank `N`, the strings to split. If `rank(input)` is not known statically, then it is assumed to be `1`. |\n| `sep` | `0-D` string `Tensor`, the delimiter character. |\n| `maxsplit` | An `int`. If `maxsplit \u003e 0`, limit of the split of the result. |\n| `result_type` | The tensor type for the result: one of `\"RaggedTensor\"` or `\"SparseTensor\"`. |\n| `source` | alias for \"input\" argument. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------|\n| `ValueError` | If sep is not a string. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `SparseTensor` or `RaggedTensor` of rank `N+1`, the strings split according to the delimiter. ||\n\n\u003cbr /\u003e"]]