class_docstr: Data collator used for language modeling that masks entire words.
  
  - collates batches of tensors, honoring their tokenizer's pad_token
  - preprocesses batches for masked language modeling
  
  <Tip>
  
  This collator relies on details of the implementation of subword tokenization by [`BertTokenizer`], specifically
  that subword tokens are prefixed with *##*. For tokenizers that do not adhere to this scheme, this collator will
  produce an output that is roughly equivalent to [`.DataCollatorForLanguageModeling`].
  
  </Tip>
class_docstr_tok: ["Data","collator","used","for","language","modeling","that","masks","entire","words",".","-","collates","batches","of","tensors",",","honoring","their","tokenizer","'s","pad_token","-","preprocesses","batches","for","masked","language","modeling","<","Tip",">","This","collator","relies","on","details","of","the","implementation","of","subword","tokenization","by","[","`","BertTokenizer","`","]",",","specifically","that","subword","tokens","are","prefixed","with","*","#","#","*",".","For","tokenizers","that","do","not","adhere","to","this","scheme",",","this","collator","will","produce","an","output","that","is","roughly","equivalent","to","[","`",".DataCollatorForLanguageModeling","`","]",".","<","\/Tip",">"]
docstr: Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original. Set
  'mask_labels' means we use whole word mask (wwm), we directly mask idxs according to it's ref.
docstr_tok: ["Prepare","masked","tokens","inputs\/labels","for","masked","language","modeling",":","80","%","MASK",",","10","%","random",",","10","%","original",".","Set","'mask_labels","'","means","we","use","whole","word","mask","(","wwm",")",",","we","directly","mask","idxs","according","to","it","'s","ref","."]
code: def torch_mask_tokens(
      self, inputs: Any, mask_labels: Any
  ) -> Tuple[Any, Any]:
      """
      Prepare masked tokens inputs/labels for masked language modeling: 80% MASK, 10% random, 10% original. Set
      'mask_labels' means we use whole word mask (wwm), we directly mask idxs according to it's ref.
      """
      import torch
  
      if self.tokenizer.mask_token is None:
          raise ValueError(
              "This tokenizer does not have a mask token which is necessary for masked language modeling. Remove the"
              " --mlm flag if you want to use this tokenizer."
          )
      labels = inputs.clone()
      # We sample a few tokens in each sequence for masked-LM training (with probability args.mlm_probability defaults to 0.15 in Bert/RoBERTa)
  
      probability_matrix = mask_labels
  
      special_tokens_mask = [
          self.tokenizer.get_special_tokens_mask(
              val, already_has_special_tokens=True
          )
          for val in labels.tolist()
      ]
      probability_matrix.masked_fill_(
          torch.tensor(special_tokens_mask, dtype=torch.bool), value=0.0
      )
      if self.tokenizer._pad_token is not None:
          padding_mask = labels.eq(self.tokenizer.pad_token_id)
          probability_matrix.masked_fill_(padding_mask, value=0.0)
  
      masked_indices = probability_matrix.bool()
      labels[
          ~masked_indices
      ] = -100  # We only compute loss on masked tokens
  
      # 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.tokenizer.convert_tokens_to_ids(
          self.tokenizer.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=torch.long
      )
      inputs[indices_random] = random_words[indices_random]
  
      # The rest of the time (10% of the time) we keep the masked input tokens unchanged
      return inputs, labels
  
imports: import random
  import warnings
  from collections.abc import Mapping
  from dataclasses import dataclass
  from random import randint
  from typing import Any, Callable, Dict, List, NewType, Optional, Tuple, Union
  import numpy
  from ..models.bert import BertTokenizer, BertTokenizerFast
  from ..tokenization_utils_base import PreTrainedTokenizerBase
  from ..utils import PaddingStrategy
label_desc: Use image node_id 5 for calling the DataCollatorForWholeWordMask obj's underlying member method code with example usage: obj.torch_mask_tokens(inputs, mask_labels) and returns: inputs,  labels