Crate caffe2op_mask
source ·Structs
- | Given a tensor of int32
lengths
tensor | representing segment lengths and a |mask
(boolean) tensor, return the | segment lengths of the corresponding | segmented tensor after BooleanMask* | is applied. | | Iflengths
tensor is $[a_1, a_2, …, | a_n]$, then length ofmask
tensor | must be $a_1 + a_2 + … + a_n$. | | Github Links: | | - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/boolean_mask_ops.cc | - | Given a 1D
data
tensor and a boolean |mask
tensor of the same shape, returns | amasked_data
tensor containing | only the elements corresponding to | positions where themask
is True, | and amasked_indices
tensor containing | the indices of the True elements. | | Github Links: | | - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/boolean_mask_ops.cc | - | Given a series of masks and values, | reconstruct values together according | to masks. | | Github Links: | | - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/boolean_unmask_ops.cc |
- | Mask op designed for use in attention mechanisms | for sequence modeling tasks. | | Supports batching: given batch_dim, collapses dims | 0 through batch_dim into a single dimension, | e.g. if tensor dims are [4,2,1,3,4] and | batch_dim=2, first collapse tensor to [421,3,4], | then mask each batch [i,:,:]. | | Two current operating modes: | | 1) Given a 2D input tensor and 1D tensor of | sequence lengths, for each row i in the input | tensor, set elements in that row to -inf if their | column index j >= sequence_lengths[i]. This mode | takes two inputs and argument mode = ‘sequence’ | | 2) Triangular mask. Given row index i and column | index j, set elements to -inf given the following | conditions: | | mode=‘upper’, x_ij = -inf if j < i | mode=‘lower’, x_ij = -inf if j > i | mode=‘upperdiag’, x_ij = -inf if j <= i | mode=‘lowerdiag’, x_ij = -inf if j >= i | | This mode takes one input. | | 3) Window Mask. Given a 2D input tensor and 1D | tensor of window centers, for each row i in the | input tensor, set elements in that row to -inf if | their column index j outside [center - radius, | center + radius]. | | This mode takes two inputs and argument mode | = ‘sequence’. | | Argument ‘radius’ should be provided.
Constants
Functions
- | Template this on a functor object so | we can generate different implementations | at compile time and have a better chance | of inlining |
- | Repeat masking along continuous segments | (right axes) of size D |