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,
  ):
      """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.
      """
  
      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,
      )
  
      # 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: ColossalAI/examples/tutorial/sequence_parallel/data/datasets/bert_dataset.py
imports: import os
  import time
  import numpy
  import torch
  from torch.utils.data import Dataset
  from colossalai.legacy.context import ParallelMode
  from colossalai.legacy.core import global_context
  from colossalai.logging import get_dist_logger
  from ..tokenizer import get_tokenizer
  from .dataset_utils import create_masked_lm_predictions, create_tokens_and_tokentypes, get_a_and_b_segments, pad_and_convert_to_numpy, truncate_segments
label_desc: Use image node_id 2 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) and returns: train_sample