code: def build_training_sample(
      sample,
      target_seq_length,
      max_seq_length,
      vocab_id_list,
      vocab_id_to_token_dict,
      cls_id,
      sep_id,
      mask_id,
      pad_id,
      masked_lm_prob,
      np_rng,
      binary_head,
      whole_word_masking=True,
      skip_masking_id=None,
  ):
      """Biuld 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.
          whole_word_masking: Whether to mask only whole words instead of independent subwords.
          skip_mask_id: ID of a token that should not be masked. #TODO: make this a list of tokens.
      """
      if binary_head:
          # We assume that we have at least two sentences in the sample
          assert len(sample) > 1
      assert target_seq_length <= max_seq_length
  
      # Divide sample into two segments (A and B).
      if binary_head:
          tokens_a, tokens_b, is_next_random = get_a_and_b_segments(
              sample, np_rng
          )
      else:
          tokens_a = []
          for j in range(len(sample)):
              tokens_a.extend(sample[j])
          tokens_b = []
          is_next_random = False
  
      # Truncate to `target_sequence_length`.
      max_num_tokens = target_seq_length
      truncated = truncate_segments(
          tokens_a,
          tokens_b,
          len(tokens_a),
          len(tokens_b),
          max_num_tokens,
          np_rng,
      )
  
      # Build tokens and toketypes.
      tokens, tokentypes = create_tokens_and_tokentypes(
          tokens_a, tokens_b, cls_id, sep_id
      )
  
      # Masking.
      max_predictions_per_seq = masked_lm_prob * max_num_tokens
      (
          tokens,
          masked_positions,
          masked_labels,
          _,
          _,
      ) = create_masked_lm_predictions(
          tokens,
          vocab_id_list,
          vocab_id_to_token_dict,
          masked_lm_prob,
          cls_id,
          sep_id,
          mask_id,
          max_predictions_per_seq,
          np_rng,
          whole_word_masking=whole_word_masking,
          skip_masking_id=skip_masking_id,
      )
  
      # Padding.
      (
          tokens_np,
          tokentypes_np,
          labels_np,
          padding_mask_np,
          loss_mask_np,
      ) = pad_and_convert_to_numpy(
          tokens,
          tokentypes,
          masked_positions,
          masked_labels,
          pad_id,
          max_seq_length,
      )
  
      train_sample = {
          "text": tokens_np,
          "types": tokentypes_np,
          "labels": labels_np,
          "is_random": int(is_next_random),
          "loss_mask": loss_mask_np,
          "padding_mask": padding_mask_np,
          "truncated": int(truncated),
      }
      return train_sample
  
file_path: NeMo/nemo/collections/nlp/data/language_modeling/megatron/bert_dataset.py
imports: import os
  from typing import Any, Optional
  import numpy
  import torch
  from nemo.collections.nlp.data.language_modeling.megatron.dataset_utils import create_masked_lm_predictions, create_tokens_and_tokentypes, get_a_and_b_segments, get_samples_mapping, truncate_segments
  from nemo.collections.nlp.data.language_modeling.megatron.indexed_dataset import MMapIndexedDataset
label_desc: Use image node_id 1 for calling a global function with example usage: build_training_sample(sample, target_seq_length, max_seq_length, vocab_id_list, vocab_id_to_token_dict, cls_id, sep_id, mask_id, pad_id, masked_lm_prob, np_rng, binary_head, whole_word_masking, skip_masking_id) and returns: train_sample