class_docstr: Data collator used for T5 span-masked language modeling.
  It is made sure that after masking the inputs are of length `data_args.max_seq_length` and targets are also of fixed length.
  For more information on how T5 span-masked language modeling works, one can take a look
  at the `official paper <https://arxiv.org/pdf/1910.10683.pdf>`__
  or the `official code for preprocessing <https://github.com/google-research/text-to-text-transfer-transformer/blob/master/t5/data/preprocessors.py>`__ .
  Args:
      tokenizer (:class:`~transformers.PreTrainedTokenizer` or :class:`~transformers.PreTrainedTokenizerFast`):
          The tokenizer used for encoding the data.
      noise_density (:obj:`float`):
          The probability with which to (randomly) mask tokens in the input.
      mean_noise_span_length (:obj:`float`):
          The average span length of the masked tokens.
      input_length (:obj:`int`):
          The expected input length after masking.
      target_length (:obj:`int`):
          The expected target length after masking.
      pad_token_id: (:obj:`int`):
          The pad token id of the model
      decoder_start_token_id: (:obj:`int):
          The decoder start token id of the model
class_docstr_tok: ["Data","collator","used","for","T5","span-masked","language","modeling",".","It","is","made","sure","that","after","masking","the","inputs","are","of","length","`","data_args.max_seq_length","`","and","targets","are","also","of","fixed","length",".","For","more","information","on","how","T5","span-masked","language","modeling","works",",","one","can","take","a","look","at","the","`","official","paper","<","https",":","\/\/arxiv.org\/pdf\/1910.10683.pdf",">","`","__","or","the","`","official","code","for","preprocessing","<","https",":","\/\/github.com\/google-research\/text-to-text-transfer-transformer\/blob\/master\/t5\/data\/preprocessors.py",">","`","__",".","Args",":","tokenizer","(",":","class",":","`","~transformers.PreTrainedTokenizer","`","or",":","class",":","`","~transformers.PreTrainedTokenizerFast","`",")",":","The","tokenizer","used","for","encoding","the","data",".","noise_density","(",":","obj",":","`","float","`",")",":","The","probability","with","which","to","(","randomly",")","mask","tokens","in","the","input",".","mean_noise_span_length","(",":","obj",":","`","float","`",")",":","The","average","span","length","of","the","masked","tokens",".","input_length","(",":","obj",":","`","int","`",")",":","The","expected","input","length","after","masking",".","target_length","(",":","obj",":","`","int","`",")",":","The","expected","target","length","after","masking",".","pad_token_id",":","(",":","obj",":","`","int","`",")",":","The","pad","token","id","of","the","model","decoder_start_token_id",":","(",":","obj",":","`","int",")",":","The","decoder","start","token","id","of","the","model"]
docstr: Make T5 MLM Batch
  
  Args:
      features (List[Dict[str, List]]):
          - input_ids
          - attention_mask
  
  Returns:
      [type]: [description]
docstr_tok: ["Make","T5","MLM","Batch","Args",":","features","(","List","[","Dict","[","str",",","List","]","]",")",":","-","input_ids","-","attention_mask","Returns",":","[","type","]",":","[","description","]"]
code: def __call__(self, features) -> Dict[str, np.ndarray]:
      """Make T5 MLM Batch
  
      Args:
          features (List[Dict[str, List]]):
              - input_ids
              - attention_mask
  
      Returns:
          [type]: [description]
      """
      raw_input_ids = [feature["input_ids"] for feature in features]
      input_ids = self.tokenizer.pad(
          [{"input_ids": x} for x in raw_input_ids],
          padding=self.padding,
          max_length=self.max_length,
          pad_to_multiple_of=self.pad_to_multiple_of,
          return_tensors="np",
          return_attention_mask=False,
      )
      input_ids = input_ids["input_ids"]
  
      mask_indices = np.zeros_like(input_ids, dtype=bool)
      for index, x in enumerate(raw_input_ids):
          if len(x) - 1 < 2:
              # Ignore src with single token
              continue
          mask = self.random_spans_noise_mask(len(x) - 1)
          mask_indices[index, : len(mask)] = mask
  
      labels_mask = ~mask_indices
  
      input_ids_sentinel = self.create_sentinel_ids(
          mask_indices.astype(np.int8)
      )
      labels_sentinel = self.create_sentinel_ids(
          labels_mask.astype(np.int8)
      )
      features = {
          "input_ids": torch.tensor(
              self.filter_input_ids(input_ids, input_ids_sentinel)
          ),
          "labels": torch.tensor(
              self.filter_input_ids(input_ids, labels_sentinel)
          ).contiguous(),
      }
      features["attention_mask"] = features["input_ids"] > 0
  
      # prepare decoder_input_ids
      if self.model is not None and hasattr(
          self.model, "prepare_decoder_input_ids_from_labels"
      ):
          decoder_input_ids = (
              self.model.prepare_decoder_input_ids_from_labels(
                  labels=features["labels"]
              )
          )
          features["decoder_input_ids"] = decoder_input_ids
  
      return features
  
file_path: DeepKE/src/deepke/name_entity_re/cross/seq2seq/data_collator/t5mlm_data_collator.py
imports: import torch
  from dataclasses import dataclass
  from typing import Dict, Optional, Union
  import numpy
  from transformers import PreTrainedTokenizerBase, PreTrainedModel
  from transformers.file_utils import PaddingStrategy
label_desc: Use image node_id 1 for calling the DataCollatorForT5MLM obj's underlying member method code with example usage: obj.__call__(features) and returns: features