tf.raw_ops.ReverseSequence
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Reverses variable length slices.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.raw_ops.ReverseSequence
tf.raw_ops.ReverseSequence(
input, seq_lengths, seq_dim, batch_dim=0, name=None
)
This op first slices input
along the dimension batch_dim
, and for each
slice i
, reverses the first seq_lengths[i]
elements along
the dimension seq_dim
.
The elements of seq_lengths
must obey seq_lengths[i] <= input.dims[seq_dim]
,
and seq_lengths
must be a vector of length input.dims[batch_dim]
.
The output slice i
along dimension batch_dim
is then given by input
slice i
, with the first seq_lengths[i]
slices along dimension
seq_dim
reversed.
For example:
# Given this:
batch_dim = 0
seq_dim = 1
input.dims = (4, 8, ...)
seq_lengths = [7, 2, 3, 5]
# then slices of input are reversed on seq_dim, but only up to seq_lengths:
output[0, 0:7, :, ...] = input[0, 7:0:-1, :, ...]
output[1, 0:2, :, ...] = input[1, 2:0:-1, :, ...]
output[2, 0:3, :, ...] = input[2, 3:0:-1, :, ...]
output[3, 0:5, :, ...] = input[3, 5:0:-1, :, ...]
# while entries past seq_lens are copied through:
output[0, 7:, :, ...] = input[0, 7:, :, ...]
output[1, 2:, :, ...] = input[1, 2:, :, ...]
output[2, 3:, :, ...] = input[2, 3:, :, ...]
output[3, 2:, :, ...] = input[3, 2:, :, ...]
In contrast, if:
# Given this:
batch_dim = 2
seq_dim = 0
input.dims = (8, ?, 4, ...)
seq_lengths = [7, 2, 3, 5]
# then slices of input are reversed on seq_dim, but only up to seq_lengths:
output[0:7, :, 0, :, ...] = input[7:0:-1, :, 0, :, ...]
output[0:2, :, 1, :, ...] = input[2:0:-1, :, 1, :, ...]
output[0:3, :, 2, :, ...] = input[3:0:-1, :, 2, :, ...]
output[0:5, :, 3, :, ...] = input[5:0:-1, :, 3, :, ...]
# while entries past seq_lens are copied through:
output[7:, :, 0, :, ...] = input[7:, :, 0, :, ...]
output[2:, :, 1, :, ...] = input[2:, :, 1, :, ...]
output[3:, :, 2, :, ...] = input[3:, :, 2, :, ...]
output[2:, :, 3, :, ...] = input[2:, :, 3, :, ...]
Args |
input
|
A Tensor . The input to reverse.
|
seq_lengths
|
A Tensor . Must be one of the following types: int32 , int64 .
1-D with length input.dims(batch_dim) and
max(seq_lengths) <= input.dims(seq_dim)
|
seq_dim
|
An int . The dimension which is partially reversed.
|
batch_dim
|
An optional int . Defaults to 0 .
The dimension along which reversal is performed.
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor . Has the same type as input .
|
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.raw_ops.ReverseSequence\n\n\u003cbr /\u003e\n\nReverses variable length slices.\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.raw_ops.ReverseSequence`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/ReverseSequence)\n\n\u003cbr /\u003e\n\n tf.raw_ops.ReverseSequence(\n input, seq_lengths, seq_dim, batch_dim=0, name=None\n )\n\nThis op first slices `input` along the dimension `batch_dim`, and for each\nslice `i`, reverses the first `seq_lengths[i]` elements along\nthe dimension `seq_dim`.\n\nThe elements of `seq_lengths` must obey `seq_lengths[i] \u003c= input.dims[seq_dim]`,\nand `seq_lengths` must be a vector of length `input.dims[batch_dim]`.\n\nThe output slice `i` along dimension `batch_dim` is then given by input\nslice `i`, with the first `seq_lengths[i]` slices along dimension\n`seq_dim` reversed.\n\n#### For example:\n\n # Given this:\n batch_dim = 0\n seq_dim = 1\n input.dims = (4, 8, ...)\n seq_lengths = [7, 2, 3, 5]\n\n # then slices of input are reversed on seq_dim, but only up to seq_lengths:\n output[0, 0:7, :, ...] = input[0, 7:0:-1, :, ...]\n output[1, 0:2, :, ...] = input[1, 2:0:-1, :, ...]\n output[2, 0:3, :, ...] = input[2, 3:0:-1, :, ...]\n output[3, 0:5, :, ...] = input[3, 5:0:-1, :, ...]\n\n # while entries past seq_lens are copied through:\n output[0, 7:, :, ...] = input[0, 7:, :, ...]\n output[1, 2:, :, ...] = input[1, 2:, :, ...]\n output[2, 3:, :, ...] = input[2, 3:, :, ...]\n output[3, 2:, :, ...] = input[3, 2:, :, ...]\n\nIn contrast, if: \n\n # Given this:\n batch_dim = 2\n seq_dim = 0\n input.dims = (8, ?, 4, ...)\n seq_lengths = [7, 2, 3, 5]\n\n # then slices of input are reversed on seq_dim, but only up to seq_lengths:\n output[0:7, :, 0, :, ...] = input[7:0:-1, :, 0, :, ...]\n output[0:2, :, 1, :, ...] = input[2:0:-1, :, 1, :, ...]\n output[0:3, :, 2, :, ...] = input[3:0:-1, :, 2, :, ...]\n output[0:5, :, 3, :, ...] = input[5:0:-1, :, 3, :, ...]\n\n # while entries past seq_lens are copied through:\n output[7:, :, 0, :, ...] = input[7:, :, 0, :, ...]\n output[2:, :, 1, :, ...] = input[2:, :, 1, :, ...]\n output[3:, :, 2, :, ...] = input[3:, :, 2, :, ...]\n output[2:, :, 3, :, ...] = input[2:, :, 3, :, ...]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | A `Tensor`. The input to reverse. |\n| `seq_lengths` | A `Tensor`. Must be one of the following types: `int32`, `int64`. 1-D with length `input.dims(batch_dim)` and `max(seq_lengths) \u003c= input.dims(seq_dim)` |\n| `seq_dim` | An `int`. The dimension which is partially reversed. |\n| `batch_dim` | An optional `int`. Defaults to `0`. The dimension along which reversal is performed. |\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 `Tensor`. Has the same type as `input`. ||\n\n\u003cbr /\u003e"]]