tf.strings.unsorted_segment_join
Stay organized with collections
Save and categorize content based on your preferences.
Joins the elements of inputs
based on segment_ids
.
tf.strings.unsorted_segment_join(
inputs, segment_ids, num_segments, separator='', name=None
)
Computes the string join along segments of a tensor.
Given segment_ids
with rank N
and data
with rank N+M
:
output[i, k1...kM] = strings.join([data[j1...jN, k1...kM])
where the join is over all [j1...jN]
such that segment_ids[j1...jN] = i
.
Strings are joined in row-major order.
For example:
inputs = ['this', 'a', 'test', 'is']
segment_ids = [0, 1, 1, 0]
num_segments = 2
separator = ' '
tf.strings.unsorted_segment_join(inputs, segment_ids, num_segments,
separator).numpy()
array([b'this is', b'a test'], dtype=object)
inputs = [['Y', 'q', 'c'], ['Y', '6', '6'], ['p', 'G', 'a']]
segment_ids = [1, 0, 1]
num_segments = 2
tf.strings.unsorted_segment_join(inputs, segment_ids, num_segments,
separator=':').numpy()
array([[b'Y', b'6', b'6'],
[b'Y:p', b'q:G', b'c:a']], dtype=object)
Args |
inputs
|
A list of tf.Tensor objects of type tf.string .
|
segment_ids
|
A tensor whose shape is a prefix of inputs.shape and whose
type must be tf.int32 or tf.int64 . Negative segment ids are not
supported.
|
num_segments
|
A scalar of type tf.int32 or tf.int64 . Must be
non-negative and larger than any segment id.
|
separator
|
The separator to use when joining. Defaults to "" .
|
name
|
A name for the operation (optional).
|
Returns |
A tf.string tensor representing the concatenated values, using the given
separator.
|
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.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.strings.unsorted_segment_join\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/string_ops.py#L586-L640) |\n\nJoins the elements of `inputs` based on `segment_ids`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.strings.unsorted_segment_join`](https://www.tensorflow.org/api_docs/python/tf/strings/unsorted_segment_join)\n\n\u003cbr /\u003e\n\n tf.strings.unsorted_segment_join(\n inputs, segment_ids, num_segments, separator='', name=None\n )\n\nComputes the string join along segments of a tensor.\n\nGiven `segment_ids` with rank `N` and `data` with rank `N+M`: \n\n output[i, k1...kM] = strings.join([data[j1...jN, k1...kM])\n\nwhere the join is over all `[j1...jN]` such that `segment_ids[j1...jN] = i`.\n\nStrings are joined in row-major order.\n\n#### For example:\n\n inputs = ['this', 'a', 'test', 'is']\n segment_ids = [0, 1, 1, 0]\n num_segments = 2\n separator = ' '\n tf.strings.unsorted_segment_join(inputs, segment_ids, num_segments,\n separator).numpy()\n array([b'this is', b'a test'], dtype=object)\n\n inputs = [['Y', 'q', 'c'], ['Y', '6', '6'], ['p', 'G', 'a']]\n segment_ids = [1, 0, 1]\n num_segments = 2\n tf.strings.unsorted_segment_join(inputs, segment_ids, num_segments,\n separator=':').numpy()\n array([[b'Y', b'6', b'6'],\n [b'Y:p', b'q:G', b'c:a']], dtype=object)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `inputs` | A list of [`tf.Tensor`](../../tf/Tensor) objects of type [`tf.string`](../../tf#string). |\n| `segment_ids` | A tensor whose shape is a prefix of `inputs.shape` and whose type must be [`tf.int32`](../../tf#int32) or [`tf.int64`](../../tf#int64). Negative segment ids are not supported. |\n| `num_segments` | A scalar of type [`tf.int32`](../../tf#int32) or [`tf.int64`](../../tf#int64). Must be non-negative and larger than any segment id. |\n| `separator` | The separator to use when joining. Defaults to `\"\"`. |\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| Returns ------- ||\n|---|---|\n| A [`tf.string`](../../tf#string) tensor representing the concatenated values, using the given separator. ||\n\n\u003cbr /\u003e"]]