yxonic/DTransformer

The paper mentions three augmentation strategies, but I only found two in the code.

Closed this issue · 2 comments

The paper mentions three data augmentation strategies: Flip Response, Drop Item, and Swap Adjacent Items. However, I could only find code for Flip Response :
s_flip[b, i] = 1 - s_flip[b, i]
and Swap Adjacent Items:
q_[b, i], q_[b, i + 1] = q_[b, i + 1], q_[b, i]
s_[b, i], s_[b, i + 1] = s_[b, i + 1], s_[b, i].
I couldn't locate code for Drop Item. Can you provide information to help me find the code or provide the core code as in the previous examples?

yxonic commented

Drop Item strategy is achieved by applying random mask here. Pos/neg sequences will be assigned different masking to achieve the effect of the contrastive drop operation.

# mask manipulation
if self.training:
mask = mask.expand(query.size(0), -1, -1, -1).contiguous()
for b in range(query.size(0)):
# sample for each batch
if lens[b] < MIN_SEQ_LEN:
# skip for short sequences
continue
idx = random.sample(
range(lens[b] - 1), max(1, int(lens[b] * self.dropout_rate))
)
for i in idx:
mask[b, :, i + 1 :, i] = 0

Thank you very much!