docstr: Build training sample.
  Arguments:
      sample: A list of sentences in which each sentence is a list token ids.
      target_seq_length: Desired sequence length.
      max_seq_length: Maximum length of the sequence. All values are padded to
          this length.
      vocab_id_list: List of vocabulary ids. Used to pick a random id.
      vocab_id_to_token_dict: A dictionary from vocab ids to text tokens.
      cls_id: Start of example id.
      sep_id: Separator id.
      mask_id: Mask token id.
      pad_id: Padding token id.
      masked_lm_prob: Probability to mask tokens.
      np_rng: Random number genenrator. Note that this rng state should be
            numpy and not python since python randint is inclusive for
            the opper bound whereas the numpy one is exclusive.
      bos_id: start of decoder example id
      eos_id: end of generation id
      sentinel_tokens: unique value to be substituted for every replaced span
      tokenizer_type: wordpiece (BERT-style) or sentencepiece tokenizer. Used for whole word masking logic.
      max_ngram_size: maximum size of ngrams to be masked.
      mean_ngram_size: mean size of ngrams to be masked (only used if geometric_dist=True).
      geometric_dist: Uses a geometric distribution to sample ngram size.
      permutation: Permutes the ngrams.
      whole_word_masking: Always masks entire words instead of individual sub-word tokens.
      favor_long_ngrams: Favor longer ngrams over shorter ones.
      skip_masking_id: An id that will not be masked. TODO: Add supported for a list of IDs.
docstr_tok: ["Build","training","sample",".","Arguments",":","sample",":","A","list","of","sentences","in","which","each","sentence","is","a","list","token","ids",".","target_seq_length",":","Desired","sequence","length",".","max_seq_length",":","Maximum","length","of","the","sequence",".","All","values","are","padded","to","this","length",".","vocab_id_list",":","List","of","vocabulary","ids",".","Used","to","pick","a","random","id",".","vocab_id_to_token_dict",":","A","dictionary","from","vocab","ids","to","text","tokens",".","cls_id",":","Start","of","example","id",".","sep_id",":","Separator","id",".","mask_id",":","Mask","token","id",".","pad_id",":","Padding","token","id",".","masked_lm_prob",":","Probability","to","mask","tokens",".","np_rng",":","Random","number","genenrator",".","Note","that","this","rng","state","should","be","numpy","and","not","python","since","python","randint","is","inclusive","for","the","opper","bound","whereas","the","numpy","one","is","exclusive",".","bos_id",":","start","of","decoder","example","id","eos_id",":","end","of","generation","id","sentinel_tokens",":","unique","value","to","be","substituted","for","every","replaced","span","tokenizer_type",":","wordpiece","(","BERT-style",")","or","sentencepiece","tokenizer",".","Used","for","whole","word","masking","logic",".","max_ngram_size",":","maximum","size","of","ngrams","to","be","masked",".","mean_ngram_size",":","mean","size","of","ngrams","to","be","masked","(","only","used","if","geometric_dist=True",")",".","geometric_dist",":","Uses","a","geometric","distribution","to","sample","ngram","size",".","permutation",":","Permutes","the","ngrams",".","whole_word_masking",":","Always","masks","entire","words","instead","of","individual","sub-word","tokens",".","favor_long_ngrams",":","Favor","longer","ngrams","over","shorter","ones",".","skip_masking_id",":","An","id","that","will","not","be","masked",".","TODO",":","Add","supported","for","a","list","of","IDs","."]
code: def build_training_sample(
      cls,
      sample,
      target_seq_length,
      np_rng,
      max_seq_length,
      max_seq_length_dec,
      masked_lm_prob,
      vocab_id_list,
      vocab_id_to_token_dict,
      cls_id,
      sep_id,
      mask_id,
      max_ngram_size,
      whole_word_masking,
      favor_long_ngrams,
      permutation,
      mean_ngram_size,
      geometric_dist,
      tokenizer_type,
      sentinel_tokens,
      bos_id,
      eos_id,
      pad_id,
      skip_masking_id=None,
  ):
      """Build training sample.
      Arguments:
          sample: A list of sentences in which each sentence is a list token ids.
          target_seq_length: Desired sequence length.
          max_seq_length: Maximum length of the sequence. All values are padded to
              this length.
          vocab_id_list: List of vocabulary ids. Used to pick a random id.
          vocab_id_to_token_dict: A dictionary from vocab ids to text tokens.
          cls_id: Start of example id.
          sep_id: Separator id.
          mask_id: Mask token id.
          pad_id: Padding token id.
          masked_lm_prob: Probability to mask tokens.
          np_rng: Random number genenrator. Note that this rng state should be
                numpy and not python since python randint is inclusive for
                the opper bound whereas the numpy one is exclusive.
          bos_id: start of decoder example id
          eos_id: end of generation id
          sentinel_tokens: unique value to be substituted for every replaced span
          tokenizer_type: wordpiece (BERT-style) or sentencepiece tokenizer. Used for whole word masking logic.
          max_ngram_size: maximum size of ngrams to be masked.
          mean_ngram_size: mean size of ngrams to be masked (only used if geometric_dist=True).
          geometric_dist: Uses a geometric distribution to sample ngram size.
          permutation: Permutes the ngrams.
          whole_word_masking: Always masks entire words instead of individual sub-word tokens.
          favor_long_ngrams: Favor longer ngrams over shorter ones.
          skip_masking_id: An id that will not be masked. TODO: Add supported for a list of IDs.
      """
      assert target_seq_length <= max_seq_length
  
      # flatten sentences into one list
      tokens = [token for sentence in sample for token in sentence]
  
      # Truncate to `target_sequence_length`.
      max_num_tokens = target_seq_length
      tokens = tokens[:max_num_tokens]
  
      # Masking.
      max_predictions_per_seq = masked_lm_prob * max_num_tokens
      lm_pred = create_masked_lm_predictions(
          tokens=tokens,
          vocab_id_list=vocab_id_list,
          vocab_id_to_token_dict=vocab_id_to_token_dict,
          masked_lm_prob=masked_lm_prob,
          cls_id=cls_id,
          sep_id=sep_id,
          mask_id=mask_id,
          max_predictions_per_seq=max_predictions_per_seq,
          np_rng=np_rng,
          max_ngram_size=max_ngram_size,
          whole_word_masking=whole_word_masking,
          favor_long_ngrams=favor_long_ngrams,
          mean_ngram_size=mean_ngram_size,
          permutation=permutation,
          geometric_dist=geometric_dist,
          masking_style="t5",
          tokenizer_type=tokenizer_type,
          skip_masking_id=skip_masking_id,
      )
  
      if masked_lm_prob == 0:
          (output_tokens, masked_positions, masked_labels, _) = lm_pred
          masked_spans = None
      else:
          (
              output_tokens,
              masked_positions,
              masked_labels,
              _,
              masked_spans,
          ) = lm_pred
  
      # Padding.
      (
          tokens_enc,
          tokens_dec_in,
          labels,
          enc_mask,
          dec_mask,
          loss_mask,
      ) = T5Dataset.pad_and_convert_to_numpy(
          output_tokens=output_tokens,
          masked_positions=masked_positions,
          masked_labels=masked_labels,
          masked_spans=masked_spans,
          sentinel_tokens=sentinel_tokens,
          bos_id=bos_id,
          eos_id=eos_id,
          pad_id=pad_id,
          max_seq_length=max_seq_length,
          max_seq_length_dec=max_seq_length_dec,
      )
  
      train_sample = {
          "text_enc": tokens_enc,
          "text_dec": tokens_dec_in,
          "labels": labels,
          "loss_mask": loss_mask,
          "enc_mask": enc_mask,
          "dec_mask": dec_mask,
      }
      return train_sample
  
imports: import collections
  import os
  import numpy
  import torch
  from nemo.collections.common.tokenizers import SentencePieceTokenizer, YouTokenToMeTokenizer
  from nemo.collections.nlp.data.language_modeling.megatron.dataset_utils import create_masked_lm_predictions, get_samples_mapping
  from nemo.collections.nlp.data.language_modeling.megatron.gpt_dataset import _build_index_mappings
  from nemo.core import Dataset
label_desc: Use image node_id 7 for calling the T5Dataset obj's underlying member method code with example usage: obj.build_training_sample(cls, sample, target_seq_length, np_rng, max_seq_length, max_seq_length_dec, masked_lm_prob, vocab_id_list, vocab_id_to_token_dict, cls_id, sep_id, mask_id, max_ngram_size, whole_word_masking, favor_long_ngrams, permutation, mean_ngram_size, geometric_dist, tokenizer_type, sentinel_tokens, bos_id, eos_id, pad_id, skip_masking_id) and returns: train_sample