docstr:     The base class for inference wrapper.
  Parameters
  ----------
  cfg: dict
      The configure dictionary.
  model: nn.Module
      The model checkpoint.
      The model must support the following attributes:
          model.graph_name: str,
              The graph type, eg: "dependency".
      The model must support the following api:
          model.inference_forward(batch_graph, **kwargs)
              It is the forward process during inference.
          model.post_process()
              It is the post-process method.
      The inference wrapper will do the pipeline as follows:
          1. model.inference_forward()
          2. model.post_process()
  dataset: Dataset,
      The dataset class.
  data_item: DataItem,
      The data_item class.
  topology_builder: Union[StaticGraphConstructionBase, DynamicGraphConstructionBase],                             default=None
      The initial graph topology builder. It is used to custermize your own graph                 construction method. We will set the default topology builder for you                  if it is ``None`` according to ``graph_name`` in ``cfg``.
  dynamic_init_topology_builder: StaticGraphConstructionBase, default=None
      The dynamic initial graph topology builder. It is used to custermize your own                 graph construction method. We will set the default topology builder for you                if it is ``None`` according to ``dynamic_init_graph_name`` in ``cfg``.
  lower_case: bool, default=True
      TBD: move it to template
  tokenizer: function, default=nltk.word_tokenize
code: def __init__(
      self,
      cfg: dict,
      model: nn.Module,
      dataset: Dataset,
      data_item: DataItem,
      topology_builder: Union[
          StaticGraphConstructionBase, DynamicGraphConstructionBase
      ] = None,
      dynamic_init_topology_builder: StaticGraphConstructionBase = None,
      lower_case: bool = True,
      tokenizer=word_tokenize,
      **kwargs,
  ):
      """
              The base class for inference wrapper.
          Parameters
          ----------
          cfg: dict
              The configure dictionary.
          model: nn.Module
              The model checkpoint.
              The model must support the following attributes:
                  model.graph_name: str,
                      The graph type, eg: "dependency".
              The model must support the following api:
                  model.inference_forward(batch_graph, **kwargs)
                      It is the forward process during inference.
                  model.post_process()
                      It is the post-process method.
              The inference wrapper will do the pipeline as follows:
                  1. model.inference_forward()
                  2. model.post_process()
          dataset: Dataset,
              The dataset class.
          data_item: DataItem,
              The data_item class.
          topology_builder: Union[StaticGraphConstructionBase, DynamicGraphConstructionBase], \
                              default=None
              The initial graph topology builder. It is used to custermize your own graph\
                   construction method. We will set the default topology builder for you \
                   if it is ``None`` according to ``graph_name`` in ``cfg``.
          dynamic_init_topology_builder: StaticGraphConstructionBase, default=None
              The dynamic initial graph topology builder. It is used to custermize your own \
                  graph construction method. We will set the default topology builder for you\
                  if it is ``None`` according to ``dynamic_init_graph_name`` in ``cfg``.
          lower_case: bool, default=True
              TBD: move it to template
          tokenizer: function, default=nltk.word_tokenize
          """
      super().__init__()
      # cfg is expected to be fixed
      # TODO: lower_case and tokenizer should be removed
      self.cfg = cfg
      self.model = model
      self.graph_name = model.graph_name
      self.dynamic_init_graph_name = cfg["graph_construction_args"][
          "graph_construction_private"
      ].get("dynamic_init_graph_name", None)
      self.lower_case = lower_case
      self.topology_builder = topology_builder
      self.dynamic_init_topology_builder = dynamic_init_topology_builder
      self.tokenizer = tokenizer
  
      self.port = self.cfg["graph_construction_args"][
          "graph_construction_share"
      ]["port"]
      self.timeout = self.cfg["graph_construction_args"][
          "graph_construction_share"
      ]["timeout"]
  
      self.merge_strategy = self.cfg["graph_construction_args"][
          "graph_construction_private"
      ]["merge_strategy"]
      self.edge_strategy = self.cfg["graph_construction_args"][
          "graph_construction_private"
      ]["edge_strategy"]
  
      self.dataset = dataset(
          port=self.port,
          graph_name=self.graph_name,
          dynamic_init_graph_name=self.dynamic_init_graph_name,
          topology_builder=topology_builder,
          dynamic_init_topology_builder=dynamic_init_topology_builder,
          lower_case=lower_case,
          tokenizer=tokenizer,
          merge_strategy=self.merge_strategy,
          edge_strategy=self.edge_strategy,
      )
      self.data_item_class = data_item
      for k, v in kwargs.items():
          setattr(self, k, v)
  
file_path: graph4nlp/graph4nlp/pytorch/inference_wrapper/base.py
imports: import json
  from typing import Union
  import torch.nn
  from graph4nlp.pytorch.data.dataset import DataItem, Dataset, DoubleText2TextDataItem, KGCompletionDataItem, Text2LabelDataItem, Text2TreeDataItem, word_tokenize
  from graph4nlp.pytorch.modules.graph_construction.base import DynamicGraphConstructionBase, StaticGraphConstructionBase
label_desc: Use image node_id 1 to create a new InferenceWrapperBase object from inherited base classes: nn with example: obj = InferenceWrapperBase(cfg, model, dataset, data_item, topology_builder, dynamic_init_topology_builder, lower_case, tokenizer)