You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

masking.py 851 B

123456789101112131415161718192021222324
  1. import torch
  2. class TriangularCausalMask():
  3. def __init__(self, B, L, device="cpu"):
  4. mask_shape = [B, 1, L, L]
  5. with torch.no_grad():
  6. self._mask = torch.triu(torch.ones(mask_shape, dtype=torch.bool), diagonal=1).to(device)
  7. @property
  8. def mask(self):
  9. return self._mask
  10. class ProbMask():
  11. def __init__(self, B, H, L, index, scores, device="cpu"):
  12. _mask = torch.ones(L, scores.shape[-1], dtype=torch.bool).to(device).triu(1)
  13. _mask_ex = _mask[None, None, :].expand(B, H, L, scores.shape[-1])
  14. indicator = _mask_ex[torch.arange(B)[:, None, None],
  15. torch.arange(H)[None, :, None],
  16. index, :].to(device)
  17. self._mask = indicator.view(scores.shape).to(device)
  18. @property
  19. def mask(self):
  20. return self._mask

基于MindSpore的多模态股票价格预测系统研究 Informer,LSTM,RNN