class_docstr: Tranformer Module base class can be used by BERT, ERNIE, RoBERTa and so on.
class_docstr_tok: ["Tranformer","Module","base","class","can","be","used","by","BERT",",","ERNIE",",","RoBERTa","and","so","on","."]
docstr: get inputs, outputs and program from pre-trained module
  Args:
      max_seq_len (int): It will limit the total sequence returned so that it has a maximum length.
      trainable (bool): Whether fine-tune the pre-trained module parameters or not.
      num_slots(int): It's number of data inputted to the model, selectted as following options:
          - 1(default): There's only one data to be feeded in the model, e.g. the module is used for sentence classification task.
          - 2: There are two data to be feeded in the model, e.g. the module is used for text matching task (point-wise).
          - 3: There are three data to be feeded in the model, e.g. the module is used for text matching task (pair-wise).
  Returns: inputs, outputs, program.
           The inputs is a dict with keys named input_ids, position_ids, segment_ids, input_mask and task_ids
           The outputs is a dict with two keys named pooled_output and sequence_output.
docstr_tok: ["get","inputs",",","outputs","and","program","from","pre-trained","module","Args",":","max_seq_len","(","int",")",":","It","will","limit","the","total","sequence","returned","so","that","it","has","a","maximum","length",".","trainable","(","bool",")",":","Whether","fine-tune","the","pre-trained","module","parameters","or","not",".","num_slots","(","int",")",":","It","'s","number","of","data","inputted","to","the","model",",","selectted","as","following","options",":","-","1","(","default",")",":","There","'s","only","one","data","to","be","feeded","in","the","model",",","e.g",".","the","module","is","used","for","sentence","classification","task",".","-","2",":","There","are","two","data","to","be","feeded","in","the","model",",","e.g",".","the","module","is","used","for","text","matching","task","(","point-wise",")",".","-","3",":","There","are","three","data","to","be","feeded","in","the","model",",","e.g",".","the","module","is","used","for","text","matching","task","(","pair-wise",")",".","Returns",":","inputs",",","outputs",",","program",".","The","inputs","is","a","dict","with","keys","named","input_ids",",","position_ids",",","segment_ids",",","input_mask","and","task_ids","The","outputs","is","a","dict","with","two","keys","named","pooled_output","and","sequence_output","."]
code: def context(
      self,
      max_seq_len: int = None,
      trainable: bool = True,
      num_slots: int = 1,
  ) -> Tuple[dict, dict, paddle.static.Program]:
      """
      get inputs, outputs and program from pre-trained module
      Args:
          max_seq_len (int): It will limit the total sequence returned so that it has a maximum length.
          trainable (bool): Whether fine-tune the pre-trained module parameters or not.
          num_slots(int): It's number of data inputted to the model, selectted as following options:
              - 1(default): There's only one data to be feeded in the model, e.g. the module is used for sentence classification task.
              - 2: There are two data to be feeded in the model, e.g. the module is used for text matching task (point-wise).
              - 3: There are three data to be feeded in the model, e.g. the module is used for text matching task (pair-wise).
      Returns: inputs, outputs, program.
               The inputs is a dict with keys named input_ids, position_ids, segment_ids, input_mask and task_ids
               The outputs is a dict with two keys named pooled_output and sequence_output.
      """
      assert num_slots >= 1 and num_slots <= 3, (
          "num_slots must be 1, 2, or 3, but the input is %d"
          % num_slots
      )
      if not max_seq_len:
          max_seq_len = self.max_seq_len
  
      assert (
          max_seq_len <= self.MAX_SEQ_LEN and max_seq_len >= 1
      ), "max_seq_len({}) should be in the range of [1, {}]".format(
          max_seq_len, self.MAX_SEQ_LEN
      )
  
      module_program = paddle.static.Program()
      startup_program = paddle.static.Program()
      with paddle.static.program_guard(module_program, startup_program):
          with paddle.utils.unique_name.guar.guard():
              input_ids = paddle.static.data(
                  name="input_ids",
                  shape=[-1, max_seq_len, 1],
                  dtype="int64",
                  lod_level=0,
              )
              position_ids = paddle.static.data(
                  name="position_ids",
                  shape=[-1, max_seq_len, 1],
                  dtype="int64",
                  lod_level=0,
              )
              segment_ids = paddle.static.data(
                  name="segment_ids",
                  shape=[-1, max_seq_len, 1],
                  dtype="int64",
                  lod_level=0,
              )
              input_mask = paddle.static.data(
                  name="input_mask",
                  shape=[-1, max_seq_len, 1],
                  dtype="float32",
                  lod_level=0,
              )
              pooled_output, sequence_output = self.net(
                  input_ids, position_ids, segment_ids, input_mask
              )
  
              data_list = [
                  (input_ids, position_ids, segment_ids, input_mask)
              ]
              output_name_list = [
                  (pooled_output.name, sequence_output.name)
              ]
  
              if num_slots > 1:
                  input_ids_2 = paddle.static.data(
                      name="input_ids_2",
                      shape=[-1, max_seq_len, 1],
                      dtype="int64",
                      lod_level=0,
                  )
                  position_ids_2 = paddle.static.data(
                      name="position_ids_2",
                      shape=[-1, max_seq_len, 1],
                      dtype="int64",
                      lod_level=0,
                  )
                  segment_ids_2 = paddle.static.data(
                      name="segment_ids_2",
                      shape=[-1, max_seq_len, 1],
                      dtype="int64",
                      lod_level=0,
                  )
                  input_mask_2 = paddle.static.data(
                      name="input_mask_2",
                      shape=[-1, max_seq_len, 1],
                      dtype="float32",
                      lod_level=0,
                  )
                  pooled_output_2, sequence_output_2 = self.net(
                      input_ids_2,
                      position_ids_2,
                      segment_ids_2,
                      input_mask_2,
                  )
                  data_list.append(
                      (
                          input_ids_2,
                          position_ids_2,
                          segment_ids_2,
                          input_mask_2,
                      )
                  )
                  output_name_list.append(
                      (pooled_output_2.name, sequence_output_2.name)
                  )
  
              if num_slots > 2:
                  input_ids_3 = paddle.static.data(
                      name="input_ids_3",
                      shape=[-1, max_seq_len, 1],
                      dtype="int64",
                      lod_level=0,
                  )
                  position_ids_3 = paddle.static.data(
                      name="position_ids_3",
                      shape=[-1, max_seq_len, 1],
                      dtype="int64",
                      lod_level=0,
                  )
                  segment_ids_3 = paddle.static.data(
                      name="segment_ids_3",
                      shape=[-1, max_seq_len, 1],
                      dtype="int64",
                      lod_level=0,
                  )
                  input_mask_3 = paddle.static.data(
                      name="input_mask_3",
                      shape=[-1, max_seq_len, 1],
                      dtype="float32",
                      lod_level=0,
                  )
                  pooled_output_3, sequence_output_3 = self.net(
                      input_ids_3,
                      position_ids_3,
                      segment_ids_3,
                      input_mask_3,
                  )
                  data_list.append(
                      (
                          input_ids_3,
                          position_ids_3,
                          segment_ids_3,
                          input_mask_3,
                      )
                  )
                  output_name_list.append(
                      (pooled_output_3.name, sequence_output_3.name)
                  )
  
      place = paddle.CPUPlace()
      exe = paddle.static.Executor(place)
  
      # To be compatible with the module v1
      vars = filter(
          lambda var: var
          not in [
              "input_ids",
              "position_ids",
              "segment_ids",
              "input_mask",
              "input_ids_2",
              "position_ids_2",
              "segment_ids_2",
              "input_mask_2",
              "input_ids_3",
              "position_ids_3",
              "segment_ids_3",
              "input_mask_3",
          ],
          list(module_program.global_block().vars.keys()),
      )
      paddle_utils.add_vars_prefix(
          program=module_program, prefix=self.param_prefix(), vars=vars
      )
      self.init_pretraining_params(
          exe, self.params_path, main_program=module_program
      )
  
      self.params_layer = {}
      for param in module_program.global_block().iter_parameters():
          param.trainable = trainable
          match = re.match(r".*layer_(\d+).*", param.name)
          if match:
              # layer num begins from 0
              layer = match.group(1)
              self.params_layer[param.name] = int(layer)
  
      inputs = {}
      outputs = {}
      for index, data in enumerate(data_list):
          if index == 0:
              inputs["input_ids"] = data[0]
              inputs["position_ids"] = data[1]
              inputs["segment_ids"] = data[2]
              inputs["input_mask"] = data[3]
              outputs[
                  "pooled_output"
              ] = module_program.global_block().vars[
                  self.param_prefix() + output_name_list[0][0]
              ]
              outputs[
                  "sequence_output"
              ] = module_program.global_block().vars[
                  self.param_prefix() + output_name_list[0][1]
              ]
          else:
              inputs["input_ids_%s" % (index + 1)] = data[0]
              inputs["position_ids_%s" % (index + 1)] = data[1]
              inputs["segment_ids_%s" % (index + 1)] = data[2]
              inputs["input_mask_%s" % (index + 1)] = data[3]
              outputs[
                  "pooled_output_%s" % (index + 1)
              ] = module_program.global_block().vars[
                  self.param_prefix() + output_name_list[index][0]
              ]
              outputs[
                  "sequence_output_%s" % (index + 1)
              ] = module_program.global_block().vars[
                  self.param_prefix() + output_name_list[index][1]
              ]
  
      return inputs, outputs, module_program
  
imports: import argparse
  import ast
  import os
  import re
  from typing import Any
  from typing import List
  from typing import Text
  from typing import Tuple
  import numpy
  import paddle
  import six
  from paddle.framework import core
  from paddlehub.compat import paddle_utils
  from paddlehub.compat.task.config import RunConfig
  from paddlehub.compat.task.reader import ClassifyReader
  from paddlehub.compat.task.transformer_emb_task import TransformerEmbeddingTask
  from paddlehub.module.module import RunModule
  from paddlehub.module.module import runnable
  from paddlehub.utils.parser import txt_parser
  from paddlehub.utils.utils import sys_stdin_encoding
label_desc: Use image node_id 4 for calling the TransformerModule obj's underlying member method code with example usage: obj.context(max_seq_len, trainable, num_slots) and returns: inputs,  outputs,  module_program