Hi, Is there an idiomatic way to do a batched shuffle of feature vectors?
I want to generate K negative samples per batch of data. i.e, given a tensor with shape (Batch x Features), I want to generate noise with the shape (K x Batch x Features), where the features in the noise are shuffled versions of the original data. e.g. given a batch like [ [ a b c ] [ a d e ] [ b d e ] ]
, I want to generate two negative examples per datum like so:
a b c a c b | c b a
a d e -> a e d | d e a
b d e b d e | e b d
I’ve tried doing this using randperm, but it is prohibitively slow, especially on the GPU, and requires a lot of logistics and scaffolding.