Let N be the size of source (typically N will be the batch size). Split each
element of source based on delimiter and return a SparseTensor
or RaggedTensor containing the split tokens. Empty tokens are ignored.
If sep is an empty string, each element of the source is split
into individual strings, each containing one byte. (This includes splitting
multibyte sequences of UTF-8.) If delimiter contains multiple bytes, it is
treated as a set of delimiters with each considered a potential split point.
Examples:
print(tf.compat.v1.string_split(['hello world','a b c']))SparseTensor(indices=tf.Tensor([[00][01][10][11][12]],...),values=tf.Tensor([b'hello'b'world'b'a'b'b'b'c'],...),dense_shape=tf.Tensor([23],shape=(2,),dtype=int64))
print(tf.compat.v1.string_split(['hello world','a b c'],result_type="RaggedTensor"))<tf.RaggedTensor[[b'hello',b'world'],[b'a',b'b',b'c']]>
Args
source
1-D string Tensor, the strings to split.
sep
0-D string Tensor, the delimiter character, the string should
be length 0 or 1. Default is ' '.
skip_empty
A bool. If True, skip the empty strings from the result.
delimiter
deprecated alias for sep.
result_type
The tensor type for the result: one of "RaggedTensor" or
"SparseTensor".
name
A name for the operation (optional).
Raises
ValueError
If delimiter is not a string.
Returns
A SparseTensor or RaggedTensor of rank 2, the strings split according
to the delimiter. The first column of the indices corresponds to the row
in source and the second column corresponds to the index of the split
component in this row.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.string_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#L528-L588) |\n\nSplit elements of `source` based on `delimiter`. (deprecated arguments) \n\n tf.compat.v1.string_split(\n source,\n sep=None,\n skip_empty=True,\n delimiter=None,\n result_type='SparseTensor',\n name=None\n )\n\n| **Deprecated:** SOME ARGUMENTS ARE DEPRECATED: `(delimiter)`. They will be removed in a future version. Instructions for updating: delimiter is deprecated, please use sep instead.\n\nLet N be the size of `source` (typically N will be the batch size). Split each\nelement of `source` based on `delimiter` and return a `SparseTensor`\nor `RaggedTensor` containing the split tokens. Empty tokens are ignored.\n\nIf `sep` is an empty string, each element of the `source` is split\ninto individual strings, each containing one byte. (This includes splitting\nmultibyte sequences of UTF-8.) If delimiter contains multiple bytes, it is\ntreated as a set of delimiters with each considered a potential split point.\n\n#### Examples:\n\n print(tf.compat.v1.string_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.string_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\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|-----------------------------------------------------------------------------------------------------|\n| `source` | `1-D` string `Tensor`, the strings to split. |\n| `sep` | `0-D` string `Tensor`, the delimiter character, the string should be length 0 or 1. Default is ' '. |\n| `skip_empty` | A `bool`. If `True`, skip the empty strings from the result. |\n| `delimiter` | deprecated alias for `sep`. |\n| `result_type` | The tensor type for the result: one of `\"RaggedTensor\"` or `\"SparseTensor\"`. |\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 delimiter 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 `2`, the strings split according to the delimiter. The first column of the indices corresponds to the row in `source` and the second column corresponds to the index of the split component in this row. ||\n\n\u003cbr /\u003e"]]