Splits a tensor in depth. Args: inputs: A ``tf.Tensor`` of shape :math:`[B, T, D]`. num_heads: The number of heads :math:`H`. Returns: A ``tf.Tensor`` of shape :math:`[B, H, T, D / H]`.
(inputs, num_heads)
| 31 | |
| 32 | |
| 33 | def split_heads(inputs, num_heads): |
| 34 | """Splits a tensor in depth. |
| 35 | |
| 36 | Args: |
| 37 | inputs: A ``tf.Tensor`` of shape :math:`[B, T, D]`. |
| 38 | num_heads: The number of heads :math:`H`. |
| 39 | |
| 40 | Returns: |
| 41 | A ``tf.Tensor`` of shape :math:`[B, H, T, D / H]`. |
| 42 | """ |
| 43 | static_shape = inputs.get_shape().as_list() |
| 44 | depth = static_shape[-1] |
| 45 | outputs = tf.reshape( |
| 46 | inputs, [tf.shape(inputs)[0], tf.shape(inputs)[1], num_heads, depth // num_heads]) |
| 47 | outputs = tf.transpose(outputs, perm=[0, 2, 1, 3]) |
| 48 | return outputs |
| 49 | |
| 50 | |
| 51 | def build_sequence_mask(sequence_length, |
nothing calls this directly
no outgoing calls
no test coverage detected