code: def convert_examples_to_features(
      examples, tokenizer, max_seq_length, doc_stride, max_query_length
  ):
      """Loads a data file into a list of `InputBatch`s."""
  
      res_input_ids = []
      res_input_mask = []
      res_segment_ids = []
      extra = []
      unique_id = 0
  
      for example_index, example in enumerate(examples):
          query_tokens = tokenizer.tokenize(example.question_text)
  
          if len(query_tokens) > max_query_length:
              query_tokens = query_tokens[0:max_query_length]
  
          tok_to_orig_index = []
          orig_to_tok_index = []
          all_doc_tokens = []
          for i, token in enumerate(example.doc_tokens):
              orig_to_tok_index.append(len(all_doc_tokens))
              sub_tokens = tokenizer.tokenize(token)
              for sub_token in sub_tokens:
                  tok_to_orig_index.append(i)
                  all_doc_tokens.append(sub_token)
  
          # The -3 accounts for [CLS], [SEP] and [SEP]
          max_tokens_for_doc = max_seq_length - len(query_tokens) - 3
  
          # We can have documents that are longer than the maximum sequence length.
          # To deal with this we do a sliding window approach, where we take chunks
          # of the up to our max length with a stride of `doc_stride`.
          _DocSpan = collections.namedtuple(
              "DocSpan", ["start", "length"]
          )
          doc_spans = []
          start_offset = 0
          while start_offset < len(all_doc_tokens):
              length = len(all_doc_tokens) - start_offset
              if length > max_tokens_for_doc:
                  length = max_tokens_for_doc
              doc_spans.append(
                  _DocSpan(start=start_offset, length=length)
              )
              if start_offset + length == len(all_doc_tokens):
                  break
              start_offset += min(length, doc_stride)
  
          for doc_span_index, doc_span in enumerate(doc_spans):
              tokens = []
              token_to_orig_map = {}
              token_is_max_context = {}
              segment_ids = []
              tokens.append("[CLS]")
              segment_ids.append(0)
              for token in query_tokens:
                  tokens.append(token)
                  segment_ids.append(0)
              tokens.append("[SEP]")
              segment_ids.append(0)
  
              for i in range(doc_span.length):
                  split_token_index = doc_span.start + i
                  token_to_orig_map[len(tokens)] = tok_to_orig_index[
                      split_token_index
                  ]
  
                  is_max_context = _check_is_max_context(
                      doc_spans, doc_span_index, split_token_index
                  )
                  token_is_max_context[len(tokens)] = is_max_context
                  tokens.append(all_doc_tokens[split_token_index])
                  segment_ids.append(1)
              tokens.append("[SEP]")
              segment_ids.append(1)
  
              input_ids = tokenizer.convert_tokens_to_ids(tokens)
  
              # The mask has 1 for real tokens and 0 for padding tokens. Only real
              # tokens are attended to.
              input_mask = [1] * len(input_ids)
  
              # Zero-pad up to the sequence length.
              while len(input_ids) < max_seq_length:
                  input_ids.append(0)
                  input_mask.append(0)
                  segment_ids.append(0)
              res_input_ids.append(np.array(input_ids, dtype=np.int64))
              res_input_mask.append(
                  np.array(input_mask, dtype=np.int64)
              )
              res_segment_ids.append(
                  np.array(segment_ids, dtype=np.int64)
              )
              feature = Feature(
                  unique_id=unique_id,
                  tokens=tokens,
                  example_index=example_index,
                  token_to_orig_map=token_to_orig_map,
                  token_is_max_context=token_is_max_context,
              )
              extra.append(feature)
              unique_id += 1
      return (
          np.array(res_input_ids),
          np.array(res_input_mask),
          np.array(res_segment_ids),
          extra,
      )
  
file_path: singa/examples/onnx/bert/run_onnx_squad.py
imports: import collections
  import json
  import math
  import numpy
  import six
  import tokenization
label_desc: Use image node_id 2 for calling a global function with example usage: convert_examples_to_features(examples, tokenizer, max_seq_length, doc_stride, max_query_length) and returns: np,  np,  np,  extra