| 13 | |
| 14 | |
| 15 | class ProbMask(): |
| 16 | def __init__(self, B, H, L, index, scores, device="cpu"): |
| 17 | _mask = torch.ones(L, scores.shape[-1], dtype=torch.bool).to(device).triu(1) |
| 18 | _mask_ex = _mask[None, None, :].expand(B, H, L, scores.shape[-1]) |
| 19 | indicator = _mask_ex[torch.arange(B)[:, None, None], |
| 20 | torch.arange(H)[None, :, None], |
| 21 | index, :].to(device) |
| 22 | self._mask = indicator.view(scores.shape).to(device) |
| 23 | |
| 24 | @property |
| 25 | def mask(self): |
| 26 | return self._mask |
| 27 | |
| 28 | |
| 29 | class LocalMask(): |