code: def main():
      """Main function."""
      time_start = time.time()
  
      # random seed
      random.seed(args.random_seed)
  
      # create output dir
      output_dir = os.path.expanduser(args.output_dir)
      if not os.path.exists(output_dir):
          os.mkdir(output_dir)
      # vocabulary and tokenizer
      _, tokenizer, _, _ = get_pretrained_bert(
          args.model_name, load_backbone=False, load_mlm=False
      )
      # count the number of input files
      input_files = []
      datasets = args.input_dir.split(",")
      for dataset in datasets:
          tmp_names = os.listdir(dataset)
          for file in tmp_names:
              input_files.append(
                  os.path.expanduser(os.path.join(dataset, file))
              )
  
      # seperate input_files
      total_num = len(input_files)
      part_num = total_num // args.shard_num
      input_files.sort()
      input_files = input_files[
          part_num
          * args.current_shard : min(
              part_num * (args.current_shard + 1), total_num
          )
      ]
  
      for input_file in input_files:
          logging.info("\t%s", input_file)
      num_inputs = len(input_files)
      num_outputs = min(args.num_outputs, len(input_files))
      logging.info("*** Reading from %d input files ***", num_inputs)
  
      # calculate the number of splits
      file_splits = []
      split_size = (num_inputs + num_outputs - 1) // num_outputs
      for i in range(num_outputs):
          split_start = i * split_size
          split_end = min(num_inputs, (i + 1) * split_size)
          file_splits.append(input_files[split_start:split_end])
  
      # prepare workload
      count = 0
      process_args = []
  
      for i, file_split in enumerate(file_splits):
          output_file = os.path.join(
              output_dir,
              "shard-{}-{}.npz".format(
                  str(args.current_shard), str(i).zfill(3)
              ),
          )
          count += len(file_split)
          process_args.append(
              (
                  file_split,
                  tokenizer,
                  args.max_seq_length,
                  args.short_seq_prob,
                  args.masked_lm_prob,
                  args.max_predictions_per_seq,
                  args.whole_word_mask,
                  tokenizer.vocab,
                  args.dupe_factor,
                  1,
                  None,
                  output_file,
                  args.random_next_sentence,
              )
          )
  
      # sanity check
      assert count == len(input_files)
  
      # dispatch to workers
      nworker = args.num_workers
      if nworker > 1:
          pool = Pool(nworker)
          pool.map(create_training_instances, process_args)
      else:
          for process_arg in process_args:
              create_training_instances(process_arg)
  
      time_end = time.time()
      logging.info("Time cost=%.1f", time_end - time_start)
  
imports: import argparse
  import logging
  import io
  import os
  import glob
  import collections
  import warnings
  import random
  import time
  from multiprocessing import Pool
  import numpy
  from gluonnlp.models.bert import BertModel, BertForPretrain, get_pretrained_bert
  import gluonnlp
label_desc: Use image node_id 10 for calling a global function with example usage: main() without return types