jactorch.functional.masking#
Masking-related functions.
Functions
|
Convert a length vector to a mask. |
|
Reverse a padded sequence tensor along the given dimension. |
|
Compute the softmax of the tensor while ignoring some masked elements. |
|
Create an N-dimensional meshgrid-like mask, where |
|
Compute the average of the tensor while ignoring some masked elements. |
|
Compute the softmax of the tensor while ignoring some masked elements. |
Functions
- length_masked_reversed(tensor, lengths, dim=1)[source]#
Reverse a padded sequence tensor along the given dimension.
- Parameters:
- Returns:
A tensor with the same size as the input, but with each sequence reversed.
- Return type:
- length_masked_softmax(logits, lengths, dim=-1, ninf=-1e4)[source]#
Compute the softmax of the tensor while ignoring some masked elements. Unlike
masked_softmax()
, this function uses the lengths to compute the mask. When all elements are masked, the result is a uniform distribution.- Parameters:
logits – tensor to be softmaxed.
lengths – a vector of length. Batch dimensions are supported, but the length dimension is assumed to be the last one.
dim – the dimension to be softmaxed.
ninf – the value to be used for masked elements.
- Returns:
the softmax of the input tensor.
- mask_meshgrid(mask, target_dims=2)[source]#
Create an N-dimensional meshgrid-like mask, where
output[i, j, k, ...] = mask[i] * mask[j] * mask[k] * ...
.
- masked_average(tensor, mask, eps=1e-8)[source]#
Compute the average of the tensor while ignoring some masked elements.
- masked_softmax(logits, mask=None, dim=-1, eps=1e-20, ninf=-1e4)[source]#
Compute the softmax of the tensor while ignoring some masked elements. When all elements are masked, the result is a uniform distribution.
- Parameters:
logits – tensor to be softmaxed.
mask – a mask indicating the element-wise weight.
dim – the dimension to be softmaxed.
eps – eps for numerical stability.
ninf – the value to be used for masked elements.
- Returns:
the softmax of the input tensor.