MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / build_sequence_mask

Function build_sequence_mask

examples/tensorflow/bert/utils/bert.py:254–274  ·  view source on GitHub ↗

Builds the dot product mask. Args: sequence_length: The sequence length. num_heads: The number of heads. maximum_length: Optional size of the returned time dimension. Otherwise it is the maximum of :obj:`sequence_length`. dtype: The type of the mask tensor

(sequence_length,
                        num_heads=None,
                        maximum_length=None,
                        dtype=tf.float32)

Source from the content-addressed store, hash-verified

252 return prev_output
253
254def build_sequence_mask(sequence_length,
255 num_heads=None,
256 maximum_length=None,
257 dtype=tf.float32):
258 """Builds the dot product mask.
259 Args:
260 sequence_length: The sequence length.
261 num_heads: The number of heads.
262 maximum_length: Optional size of the returned time dimension. Otherwise
263 it is the maximum of :obj:`sequence_length`.
264 dtype: The type of the mask tensor.
265 Returns:
266 A broadcastable ``tf.Tensor`` of type :obj:`dtype` and shape
267 ``[batch_size, 1, max_length, max_length]``.
268 """
269 mask = tf.sequence_mask(sequence_length, maxlen=maximum_length, dtype=dtype) # [batch_size, maximum_length]
270 mask = tf.reshape(mask, [-1, 1, 1, maximum_length])
271 m_2 = tf.transpose(mask, [0, 1, 3, 2])
272 mask = mask * m_2
273
274 return mask
275
276def get_shape_list(tensor, expected_rank=None, name=None):
277 if name is None:

Callers 1

bert_exampleFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected