How to select 3D tensor from a 2D mask? - PyTorch Forums
discuss.pytorch.org › t › how-to-select-3d-tensorOct 13, 2020 · Hi I have a 3D tensor like (batch_size, seq_len, dim), and some of them in the 2nd dimension are zero-padded. And I have a mask generated by the lengths. I want to select the tensor by the mask. The behavior is like masked_select but returns a 2D tensor. a = torch.rand((3, 3, 3)) a[1, 2] = 0 a[2, 2] = 0 a[2, 1] = 0 print(a) tensor([[[0.7910, 0.4829, 0.7381], [0.9005, 0.2266, 0.5940], [0.8811 ...
How to select tensor's columns by mask? - PyTorch Forums
discuss.pytorch.org › t › how-to-select-tensorsJul 14, 2018 · For example I have 3d tensor like this: a = torch.ones((3, 3, 3)) a[:, 1, 1] = 2 a[:, 2, 2] = 5 And I have a 2d “mask” like this: b = torch.zeros((3, 3)) b[1, 1] = 1 b[2, 2] = 1 And I want to get a list of 3d vectors from ‘a’ by mask ‘b’: the output should contain two vectors: [[2, 2, 2], [5, 5, 5]] I tried to use some constructions like torch.masked_select, but it always return 1d ...
MultiheadAttention — PyTorch 1.10.1 documentation
pytorch.org › docs › stableA 2D mask will be broadcasted across the batch while a 3D mask allows for a different mask for each entry in the batch. Binary, byte, and float masks are supported. For a binary mask, a True value indicates that the corresponding position is not allowed to attend. For a byte mask, a non-zero value indicates that the corresponding position is ...
torch.masked_select — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.masked_select. Returns a new 1-D tensor which indexes the input tensor according to the boolean mask mask which is a BoolTensor. The shapes of the mask tensor and the input tensor don’t need to match, but they must be broadcastable. input ( Tensor) – the input tensor. out ( Tensor, optional) – the output tensor.
How to select 3D tensor from a 2D mask? - PyTorch Forums
https://discuss.pytorch.org/t/how-to-select-3d-tensor-from-a-2d-mask/9915313.10.2020 · Hi I have a 3D tensor like (batch_size, seq_len, dim), and some of them in the 2nd dimension are zero-padded. And I have a mask generated by the lengths. I want to select the tensor by the mask. The behavior is like masked_select but returns a 2D tensor. a = torch.rand((3, 3, 3)) a[1, 2] = 0 a[2, 2] = 0 a[2, 1] = 0 print(a) tensor([[[0.7910, 0.4829, 0.7381], [0.9005, …
How to select tensor's columns by mask? - PyTorch Forums
https://discuss.pytorch.org/t/how-to-select-tensors-columns-by-mask/2114514.07.2018 · For example I have 3d tensor like this: a = torch.ones((3, 3, 3)) a[:, 1, 1] = 2 a[:, 2, 2] = 5 And I have a 2d “mask” like this: b = torch.zeros((3, 3)) b[1, 1] = 1 b[2, 2] = 1 And I want to get a list of 3d vectors from ‘a’ by mask ‘b’: the output should contain two vectors: [[2, 2, 2], [5, 5, 5]] I tried to use some constructions like torch.masked_select, but it always return 1d ...