MCPcopy Create free account
hub / github.com/google-research/language / transpose_batch_time

Function transpose_batch_time

language/common/utils/tensor_utils.py:200–221  ·  view source on GitHub ↗

Transposes the batch and time dimensions of the `tensor`. If the `tensor` has less than 2 dimensions, then no operation is performed. Otherwise, swaps the first 2 dimensions, which are assumed to be the batch and time dimensions. Args: tensor: Tensor to transpose. Returns: Possi

(tensor)

Source from the content-addressed store, hash-verified

198
199
200def transpose_batch_time(tensor):
201 """Transposes the batch and time dimensions of the `tensor`.
202
203 If the `tensor` has less than 2 dimensions, then no operation is performed.
204 Otherwise, swaps the first 2 dimensions, which are assumed to be the batch and
205 time dimensions.
206
207 Args:
208 tensor: Tensor to transpose.
209
210 Returns:
211 Possibly-transposed version of `tensor`.
212
213 Raises:
214 ValueError: If the `tensor` has unknown rank.
215 """
216 rank = tensor.shape.ndims
217 if rank is None:
218 raise ValueError("Tensor with unknown rank")
219 if rank < 2:
220 return tensor
221 return tf.transpose(tensor, perm=[1, 0] + list(range(2, rank)))
222
223
224def sequence_mask(lengths, maxlen=None, dtype=tf.bool, transpose=False):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…