(lengths, maxlen=None, dtype=torch.float32, device=None)
| 281 | |
| 282 | |
| 283 | def sequence_mask(lengths, maxlen=None, dtype=torch.float32, device=None): |
| 284 | if maxlen is None: |
| 285 | maxlen = lengths.max() |
| 286 | row_vector = torch.arange(0, maxlen, 1).to(lengths.device) |
| 287 | matrix = torch.unsqueeze(lengths, dim=-1) |
| 288 | mask = row_vector < matrix |
| 289 | mask = mask.detach() |
| 290 | |
| 291 | return mask.type(dtype).to(device) if device is not None else mask.type(dtype) |
| 292 | |
| 293 | |
| 294 | class EncoderLayerSANM(nn.Module): |
no outgoing calls
no test coverage detected