code: def convert_to_npz(all_features, output_file=None):
      """
      Convert features to numpy array and store if output_file provided
  
      Parameters
      ----------
      all_features
          A list of processed features.
      output_file
          The path to a output file that store the np_features.
      Returns
      -------
      input_ids
          A tuple of features
      segment_ids
          The segment ids
      valid_lengths
          The valid lengths
      """
      input_ids = []
      segment_ids = []
      valid_lengths = []
      for fea_index, feature in enumerate(all_features):
          input_ids.append(
              np.ascontiguousarray(feature.input_id, dtype="int32")
          )
          segment_ids.append(
              np.ascontiguousarray(feature.segment_id, dtype="int32")
          )
          valid_lengths.append(feature.valid_length)
          if fea_index < 1:
              logging.debug("*** Example Feature ***")
              logging.debug("Generated {}".format(feature))
  
      if output_file:
          # The length numpy array are fixed to max_seq_length with zero padding
          npz_outputs = collections.OrderedDict()
          npz_outputs["input_ids"] = np.array(input_ids, dtype="int32")
          npz_outputs["segment_ids"] = np.array(
              segment_ids, dtype="int32"
          )
          npz_outputs["valid_lengths"] = np.array(
              valid_lengths, dtype="int32"
          )
          np.savez_compressed(output_file, **npz_outputs)
          logging.info(
              "Saved {} features in {} ".format(
                  len(all_features), output_file
              )
          )
      return input_ids, segment_ids, valid_lengths
  
imports: import io
  import os
  import re
  import random
  import logging
  import collections
  import numpy
  from mxnet import np, npx
  from mxnet.gluon import HybridBlock
  from mxnet.gluon.data import ArrayDataset
  import gluonnlp.data.batchify
  from gluonnlp.utils.misc import glob
  from gluonnlp.data.loading import NumpyDataset, DatasetLoader
  from gluonnlp.data.sampler import SplitSampler, FixedBucketSampler
  from gluonnlp.op import select_vectors_by_position, update_vectors_by_position
  from gluonnlp.initializer import TruncNorm
  from gluonnlp.models.electra import ElectraModel, ElectraForPretrain, get_pretrained_electra
label_desc: Use image node_id 4 for calling a global function with example usage: convert_to_npz(all_features, output_file) and returns: input_ids,  segment_ids,  valid_lengths