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",">"]
code: def torch_call(
      self, examples: List[Union[List[int], Any, Dict[str, Any]]]
  ) -> Dict[str, Any]:
      if isinstance(examples[0], Mapping):
          input_ids = [e["input_ids"] for e in examples]
      else:
          input_ids = examples
          examples = [{"input_ids": e} for e in examples]
  
      batch_input = _torch_collate_batch(
          input_ids,
          self.tokenizer,
          pad_to_multiple_of=self.pad_to_multiple_of,
      )
  
      mask_labels = []
      for e in examples:
          ref_tokens = []
          for id in tolist(e["input_ids"]):
              token = self.tokenizer._convert_id_to_token(id)
              ref_tokens.append(token)
  
          # For Chinese tokens, we need extra inf to mark sub-word, e.g [喜,欢]-> [喜，##欢]
          if "chinese_ref" in e:
              ref_pos = tolist(e["chinese_ref"])
              len_seq = len(e["input_ids"])
              for i in range(len_seq):
                  if i in ref_pos:
                      ref_tokens[i] = "##" + ref_tokens[i]
          mask_labels.append(self._whole_word_mask(ref_tokens))
      batch_mask = _torch_collate_batch(
          mask_labels,
          self.tokenizer,
          pad_to_multiple_of=self.pad_to_multiple_of,
      )
      inputs, labels = self.torch_mask_tokens(batch_input, batch_mask)
      return {"input_ids": inputs, "labels": 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 1 for calling the DataCollatorForWholeWordMask obj's underlying member method code with example usage: obj.torch_call(examples) and returns: dict