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 873 B

12345678910111213141516171819202122232425
  1. import mindspore
  2. import mindspore.ops.operations as P
  3. import mindspore.numpy as mnp
  4. class TriangularCausalMask():
  5. def __init__(self, B, L, device="cpu"):
  6. mask_shape = [B, 1, L, L]
  7. self._mask = mindspore.Tensor(mnp.triu(mnp.ones(mask_shape, dtype=mnp.bool_), 1).to(device))
  8. @property
  9. def mask(self):
  10. return self._mask
  11. class ProbMask():
  12. def __init__(self, B, H, L, index, scores, device="cpu"):
  13. _mask = mindspore.Tensor(mnp.triu(mnp.ones((L, scores.shape[-1]), dtype=mnp.bool_)).to(device))
  14. _mask_ex = _mask[None, None, :]
  15. indicator = _mask_ex[mnp.arange(B)[:, None, None],
  16. mnp.arange(H)[None, :, None],
  17. index, :].to(device)
  18. self._mask = indicator.view(scores.shape).to(device)
  19. @property
  20. def mask(self):
  21. return self._mask

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