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)
| 198 | |
| 199 | |
| 200 | def 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 | |
| 224 | def sequence_mask(lengths, maxlen=None, dtype=tf.bool, transpose=False): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…