class_docstr: Masked language model for BERT style pre-training.
class_docstr_tok: ["Masked","language","model","for","BERT","style","pre-training","."]
code: def _get_mask(self, tokens):
      mask = self._select_tokens_to_mask(tokens, self.mask_prob)
      pad_mask = (tokens != self.vocab.get_pad_index()).long()
      mask *= pad_mask
      if not mask.byte().any():
          # Keep one masked token to avoid failure in the loss calculation.
          mask[0, 0] = 1
  
      probs = torch.rand_like(tokens, dtype=torch.float)
      rand_mask = (probs < 0.1).long() * mask
      mask_mask = (probs >= 0.2).long() * mask
      return mask, pad_mask, mask_mask, rand_mask
  
imports: from typing import Dict, List
  import torch
  from fairseq.modules.transformer_sentence_encoder import init_bert_params
  from pytext.common.constants import SpecialTokens, Stage
  from pytext.config import ConfigBase
  from pytext.data.bert_tensorizer import BERTTensorizerBase
  from pytext.data.tensorizers import Tensorizer
  from pytext.data.utils import Vocabulary
  from pytext.models.decoders.mlp_decoder import MLPDecoder
  from pytext.models.masking_utils import frequency_based_masking, MaskingStrategy, random_masking
  from pytext.models.model import BaseModel
  from pytext.models.module import create_module
  from pytext.models.output_layers.lm_output_layer import LMOutputLayer
  from pytext.models.representations.transformer_sentence_encoder import TransformerSentenceEncoder
  from pytext.models.representations.transformer_sentence_encoder_base import TransformerSentenceEncoderBase
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 7 for calling the MaskedLanguageModel obj's underlying member method code with example usage: obj._get_mask(tokens) and returns: mask,  pad_mask,  mask_mask,  rand_mask