This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
def lengths_to_mask(lengths, max_len=None, dtype=None): | |
""" | |
Converts a "lengths" tensor to its binary mask representation. | |
Based on: https://discuss.pytorch.org/t/how-to-generate-variable-length-mask/23397 |