Warning: This API is deprecated and will be removed in a future
version of TensorFlow after
the replacement is stable.
ReverseSequence
Stay organized with collections
Save and categorize content based on your preferences.
Reverses variable length slices.
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, :, ...]
Inherited Methods
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Public Methods
public
Output<T>
asOutput
()
Returns the symbolic handle of a tensor.
Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is
used to obtain a symbolic handle that represents the computation of the input.
Parameters
batchDim |
The dimension along which reversal is performed.
|
Factory method to create a class wrapping a new ReverseSequence operation.
Parameters
scope |
current scope |
input |
The input to reverse. |
seqLengths |
1-D with length `input.dims(batch_dim)` and
`max(seq_lengths) <= input.dims(seq_dim)` |
seqDim |
The dimension which is partially reversed. |
options |
carries optional attributes values |
Returns
- a new instance of ReverseSequence
public
Output<T>
output
()
The partially reversed input. It has the same shape 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.
Last updated 2022-02-12 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 2022-02-12 UTC."],[],[],null,["# ReverseSequence\n\npublic final class **ReverseSequence** \nReverses variable length slices.\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\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\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\nFor 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\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Nested Classes\n\n|-------|---|---|--------------------------------------------------------------------------------------------------|\n| class | [ReverseSequence.Options](/api_docs/java/org/tensorflow/op/core/ReverseSequence.Options) || Optional attributes for [ReverseSequence](/api_docs/java/org/tensorflow/op/core/ReverseSequence) |\n\n### Public Methods\n\n|--------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e | [asOutput](/api_docs/java/org/tensorflow/op/core/ReverseSequence#asOutput())() Returns the symbolic handle of a tensor. |\n| static [ReverseSequence.Options](/api_docs/java/org/tensorflow/op/core/ReverseSequence.Options) | [batchDim](/api_docs/java/org/tensorflow/op/core/ReverseSequence#batchDim(java.lang.Long))(Long batchDim) |\n| static \\\u003cT, U extends Number\\\u003e [ReverseSequence](/api_docs/java/org/tensorflow/op/core/ReverseSequence)\\\u003cT\\\u003e | [create](/api_docs/java/org/tensorflow/op/core/ReverseSequence#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand\u003cT\u003e,%20org.tensorflow.Operand\u003cU\u003e,%20java.lang.Long,%20org.tensorflow.op.core.ReverseSequence.Options...))([Scope](/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e input, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cU\\\u003e seqLengths, Long seqDim, [Options...](/api_docs/java/org/tensorflow/op/core/ReverseSequence.Options) options) Factory method to create a class wrapping a new ReverseSequence operation. |\n| [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e | [output](/api_docs/java/org/tensorflow/op/core/ReverseSequence#output())() The partially reversed input. |\n\n### Inherited Methods\n\nFrom class [org.tensorflow.op.PrimitiveOp](/api_docs/java/org/tensorflow/op/PrimitiveOp) \n\n|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| final boolean | [equals](/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |\n| final int | [hashCode](/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |\n| [Operation](/api_docs/java/org/tensorflow/Operation) | [op](/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying [Operation](/api_docs/java/org/tensorflow/Operation) |\n| final String | [toString](/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface [org.tensorflow.Operand](/api_docs/java/org/tensorflow/Operand) \n\n|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| abstract [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e | [asOutput](/api_docs/java/org/tensorflow/Operand#asOutput())() Returns the symbolic handle of a tensor. |\n\nPublic Methods\n--------------\n\n#### public [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e\n**asOutput**\n()\n\nReturns the symbolic handle of a tensor.\n\nInputs to TensorFlow operations are outputs of another TensorFlow operation. This method is\nused to obtain a symbolic handle that represents the computation of the input.\n\n\u003cbr /\u003e\n\n#### public static [ReverseSequence.Options](/api_docs/java/org/tensorflow/op/core/ReverseSequence.Options)\n**batchDim**\n(Long batchDim)\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| batchDim | The dimension along which reversal is performed. |\n|----------|--------------------------------------------------|\n\n#### public static [ReverseSequence](/api_docs/java/org/tensorflow/op/core/ReverseSequence)\\\u003cT\\\u003e\n**create**\n([Scope](/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e input, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cU\\\u003e seqLengths, Long seqDim, [Options...](/api_docs/java/org/tensorflow/op/core/ReverseSequence.Options) options)\n\nFactory method to create a class wrapping a new ReverseSequence operation. \n\n##### Parameters\n\n| scope | current scope |\n| input | The input to reverse. |\n| seqLengths | 1-D with length \\`input.dims(batch_dim)\\` and \\`max(seq_lengths) \\\u003c= input.dims(seq_dim)\\` |\n| seqDim | The dimension which is partially reversed. |\n| options | carries optional attributes values |\n|------------|--------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- a new instance of ReverseSequence \n\n#### public [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e\n**output**\n()\n\nThe partially reversed input. It has the same shape as \\`input\\`."]]