BERT4Rec-VAE-Pytorch icon indicating copy to clipboard operation
BERT4Rec-VAE-Pytorch copied to clipboard

A question about the code of " BertTrainDataset.__getitem__(self, index)" function

Open JiekeLi opened this issue 5 years ago • 3 comments

I want to ask a question that why you give '0' label to the none masked token when generate a example here:

    for s in seq:
           prob = self.rng.random()
           if prob < self.mask_prob:
               prob /= self.mask_prob

               if prob < 0.8:
                   tokens.append(self.mask_token)
               elif prob < 0.9: 
                   tokens.append(self.rng.randint(1, self.num_items))
               else: 
                   tokens.append(s)

               labels.append(s) 
           else:
               tokens.append(s)
               labels.append(0) # **why give 0 label here and not the index of s ?**

Thanks !

JiekeLi avatar Sep 09 '20 11:09 JiekeLi

I was also wondering the same. Masking should only be applied to input tokens

thomalm avatar Jan 02 '21 22:01 thomalm

because loss function is CrossEntropyLoss(ignore_index=0) ,it ignored index for zero,only compute loss for mask item or random item。

but :

if prob < 0.8: 
    tokens.append(self.mask_token)
    labels.append(s)
elif prob < 0.9: 
    tokens.append(self.rng.randint(1, self.num_items))
    labels.append(s)
else: 
    tokens.append(s)
    labels.append(0)  #? I changed it.

reckzhou avatar Jun 18 '21 09:06 reckzhou

And why divide one more time using 0.8, 0.9 after mask_prob? Random item insertion on 0.15 * 0.1 ? I couldn't find this part on paper

kyeongchan92 avatar Feb 14 '23 02:02 kyeongchan92