Hi fbrah!



 fbrah:

I have a tensor of dimension (batch_size, Seq_len)
I want to mask out all values between two specific values of seq_len,


I’m confused about what you are asking.  “Seq_len” is the second
dimension of your tensor, but then you have “two specific values of
seq_len.”  I don’t understand what you mean.  Is “seq_len” an index
into your tensor, or is it the value of an element of your tensor?


for example 100, and 125. (including 100 and 125). There might be multiple such occurrences of them too.
I want to mask out with ‘-1’


If “seq_len” is an index, then you can use slice notation.  That is,
if t is your tensor, then:
t[:, 100:126] = -1.0

will overwrite the elements of your tensor whose second index is in
the range [100, 125] (inclusive) with -1.0.
If “seq_len” is a value, then if you want to replace with -1 the elements
of your tensor whose values fall in a given range, masked_fill_()
should do what you want.  That is, if t is your tensor, then:
t.masked_fill_ (t.ge (100.0) * t.le (125.0), -1.0)

will overwrite the elements of your tensor whose value fall in the
range [100.0, 125.0] (inclusive) with -1.0.
Good luck.
K. Frank