What is the best way to perform dynamic pooling (e.g. max pooling) on a Tensor? For instance:
import torch
A = torch.rand(4,10,3)
B = torch.LongTensor([[0,1],[4,4],[2,5],[7,7]])
Tensor A
represents 4 examples of length 10-token, each token is represented with a vector of size 3. Tensor B
contains 4 pairs of indices, each of which represents indices of the first and last token for each example that should be pooled. For instance, for the third example (i.e., A[2,:,:]
), max-pooling should be operated on vectors A[2,2,:]
, A[2,3,:]
, A[2,4,:]
, and A[2,5,:]
.