Link Search Menu Expand Document

ReverseSequence


tensorflowC++API

tensorflow::ops::ReverseSequence

Reversesvariablelengthslices.


Summary

This op first slicesinputalong the dimensionbatch_dim, and for each slicei, reverses the firstseq_lengths[i]elements along the dimensionseq_dim.

The elements ofseq_lengthsmust obeyseq_lengths[i] <= input.dims[seq_dim], andseq_lengthsmust be a vector of lengthinput.dims[batch_dim].

The output sliceialong dimensionbatch_dimis then given by input slicei, with the firstseq_lengths[i]slices along dimensionseq_dimreversed.

Forexample:

```Giventhis:

batch_dim=0seq_dim=1input.dims=(4,8,…)seq_lengths=[7,2,3,5]

thenslicesofinputarereversedonseq_dim,butonlyuptoseq_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,:,…]

whileentriespastseq_lensarecopiedthrough:

output[0,7:,:,…]=input[0,7:,:,…]output[1,2:,:,…]=input[1,2:,:,…]output[2,3:,:,…]=input[2,3:,:,…]output[3,2:,:,…]=input[3,2:,:,…]```

Incontrast,if:

```Giventhis:

batch_dim=2seq_dim=0input.dims=(8,?,4,…)seq_lengths=[7,2,3,5]

thenslicesofinputarereversedonseq_dim,butonlyuptoseq_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,:,…]

whileentriespastseq_lensarecopiedthrough:

output[7:,:,0,:,…]=input[7:,:,0,:,…]output[2:,:,1,:,…]=input[2:,:,1,:,…]output[3:,:,2,:,…]=input[3:,:,2,:,…]output[2:,:,3,:,…]=input[2:,:,3,:,…]```

Arguments:

  • scope: A Scope object
  • input: The input to reverse.
  • seq_lengths: 1-D with length input.dims(batch_dim) and max(seq_lengths) <= input.dims(seq_dim)
  • seq_dim: The dimension which is partially reversed.

Optional attributes (seeAttrs):

  • batch_dim: The dimension along which reversal is performed.

Returns:

  • Output: The partially reversed input. It has the same shape as input

ReverseSequenceblock

Source link :https://github.com/EXPNUNI/enuSpaceTensorflow/blob/master/enuSpaceTensorflow/tf_array_ops.cpp

Argument:

  • Scope scope : A Scope object (A scope is generated automatically each page. A scope is not connected.)
  • Input input: The input to reverse.
  • Input seq_lengths: 1-D with length input.dims(batch_dim) and max(seq_lengths) <= input.dims(seq_dim)
  • Int64 seq_dim: The dimension which is partially reversed.

Output:

  • Output output: Output object of ReverseSequence class object.

Result:

  • std::vector(Tensor) result_output: The same shape astensor.

UsingMethod

※seq_dim:대당하는차원에대해부분적으로반전을시킨다.(ex:input이이고,seq_dim=1,seq_lengths={1,2}라면결과값은이된다.)

※attr의batch_dim:반전을시키는차원을지정한다.1이면1차원,0이면영향을주지않는다.(0일경우오직seq_dim에의해영향을받음