Mask multiplication

Hi everybody,

I’m working with Seq2seq networks for NLP purposes and almost new to this Deep Learning area. Just have a question about matrix multiplication on Pytorch.

Suppose that I have these vectors:

a = shape(2, 34, 200)

b = shape (2,6, 200)
mask = shape(2,34)

mask is a 0-1 vector denoting specific tokens in a vector. (1: exists, 0: otherwise)
Here is the work I wanna do: I want to use mask vector to find the associated rows (denoted by 1 in mask) and multiply these rows by ‘b’ vector. As for this discussion, b vector associates with those rows in the a vector that has value 1 in the mask.

I think you need to be a bit more specific here:

  • what is your desired output shape?
  • what should happen when mask=0? Should for those the corresponding results be 0 or …?

Best regards