Hello,
I am completely beginner in NNs and I am currently facing the same problem.
I am trying to implement my own loss function for BERT Masked LM.
So this part of the code is the most useful for my case:

loss2 = F.cross_entropy(logits.view(-1, tokenizer.vocab_size), labels.view(-1))

However, I do not understand how I can calculate the cross entropy loss from logits and masked token ID. How do we get the information which word was originally masked? This information is completely overlooked when calling the cross entropy function. Am I missing something?