docstr: Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original.
  
  This is the orignal randomized draw.
docstr_tok: ["Prepare","masked","tokens","inputs\/labels","for","masked","language","modeling",":","80","%","MASK",",","10","%","random",",","10","%","original",".","This","is","the","orignal","randomized","draw","."]
code: def _legacy_torch_mask_tokens(
      self, inputs=None, special_tokens_mask=None
  ):
      """
      Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original.
  
      This is the orignal randomized draw.
      """
      labels = inputs.clone()
      # We sample a few tokens in each sequence for MLM training (with probability `self.mlm_probability`)
      probability_matrix = torch.full(
          labels.shape, self.mlm_probability
      )
      if special_tokens_mask is None:
          special_tokens_mask = [
              self.tokenizer.get_special_tokens_mask(
                  val, already_has_special_tokens=True
              )
              for val in labels.tolist()
          ]
          special_tokens_mask = torch.tensor(
              special_tokens_mask, dtype=torch.bool
          )
      else:
          special_tokens_mask = special_tokens_mask.bool()
  
      probability_matrix.masked_fill_(special_tokens_mask, value=0.0)
      masked_indices = torch.bernoulli(probability_matrix).bool()
  
      labels[
          ~masked_indices
      ] = -100  # We only compute loss on masked tokens
  
      if self.use_80_20_rule:
          # 80% of the time, we replace masked input tokens with tokenizer.mask_token ([MASK])
          indices_replaced = (
              torch.bernoulli(torch.full(labels.shape, 0.8)).bool()
              & masked_indices
          )
          inputs[indices_replaced] = self.mask_token
  
          # 10% of the time, we replace masked input tokens with random word
          indices_random = (
              torch.bernoulli(torch.full(labels.shape, 0.5)).bool()
              & masked_indices
              & ~indices_replaced
          )
          random_words = torch.randint(
              len(self.tokenizer), labels.shape, dtype=inputs.dtype
          )
          inputs[indices_random] = random_words[indices_random]
  
          # The rest of the time (10% of the time) we keep the masked input tokens unchanged
      else:
          # 100% of the time, we replace masked input tokens with tokenizer.mask_token ([MASK])
          inputs[masked_indices] = self.mask_token
  
      if self.token_drop > 0:
          inputs, labels = self._drop_tokens(inputs, labels)
      return inputs, labels
  
imports: import os
  import torch
  import transformers
  from torch.utils.data import DataLoader
  from datasets.distributed import split_dataset_by_node
label_desc: Use image node_id 3 for calling the PatchedDataCollatorForLanguageModeling obj's underlying member method code with example usage: obj._legacy_torch_mask_tokens(inputs, special_tokens_mask) and returns: inputs,  labels