Hi @sanaz,
I can see few mistakes here

You need to mask tokens in the input_ids not labels. And to prepare lables for masked LM set every position  to -100 (ignore index) except the masked positions.
masked loss is then calculated simply using the CrossEntropy loss between the logits and labels.

So correct usage would be
text = "Who was Jim Paterson ? Jim Paterson is a doctor".lower()
inputs  =  tokenizer([text],  return_tensors="pt")

input_ids = inputs["input_ids"]
# mask the token
input_ids[0][7] = tokenizer.mask_token_id

labels = inputs["input_ids"].clone()
labels[labels != tokenizer.mask_token_id] = -100 # only calculate loss on masked tokens

loss, logits = model(
    input_ids=input_ids,
    labels=labels,
    attention_mask=inputs["attention_mask"],
    token_type_ids=inputs["token_type_ids"]
)
# loss => 18.2054

# calculate loss manually
import torch.nn.functional as F
loss2 = F.cross_entropy(logits.view(-1, tokenizer.vocab_size), labels.view(-1))
# loss2 => 18.2054

Hope this helps.