class_docstr: A base class for text model which supports serving.
class_docstr_tok: ["A","base","class","for","text","model","which","supports","serving","."]
docstr: Run predict method as a service.
  Serving as a task which is specified from serving config.
  Tasks supported:
  1. seq-cls: sequence classification;
  2. token-cls: sequence labeling;
  3. None: embedding.
  Args:
      data (obj:`List(List(str))`): The processed data whose each element is the list of a single text or a pair of texts.
      max_seq_len (:obj:`int`, `optional`, defaults to 128):
          If set to a number, will limit the total sequence returned so that it has a maximum length.
      batch_size(obj:`int`, defaults to 1): The number of batch.
      use_gpu(obj:`bool`, defaults to `False`): Whether to use gpu to run or not.
  Returns:
      results(obj:`list`): All the predictions labels.
docstr_tok: ["Run","predict","method","as","a","service",".","Serving","as","a","task","which","is","specified","from","serving","config",".","Tasks","supported",":","1.","seq-cls",":","sequence","classification",";","2.","token-cls",":","sequence","labeling",";","3",".","None",":","embedding",".","Args",":","data","(","obj",":","`","List","(","List","(","str",")",")","`",")",":","The","processed","data","whose","each","element","is","the","list","of","a","single","text","or","a","pair","of","texts",".","max_seq_len","(",":","obj",":","`","int","`",",","`","optional","`",",","defaults","to","128",")",":","If","set","to","a","number",",","will","limit","the","total","sequence","returned","so","that","it","has","a","maximum","length",".","batch_size","(","obj",":","`","int","`",",","defaults","to","1",")",":","The","number","of","batch",".","use_gpu","(","obj",":","`","bool","`",",","defaults","to","`","False","`",")",":","Whether","to","use","gpu","to","run","or","not",".","Returns",":","results","(","obj",":","`","list","`",")",":","All","the","predictions","labels","."]
code: def predict_method(
      self,
      data: List[List[str]],
      max_seq_len: int = 128,
      batch_size: int = 1,
      use_gpu: bool = False,
  ):
      """
      Run predict method as a service.
      Serving as a task which is specified from serving config.
      Tasks supported:
      1. seq-cls: sequence classification;
      2. token-cls: sequence labeling;
      3. None: embedding.
      Args:
          data (obj:`List(List(str))`): The processed data whose each element is the list of a single text or a pair of texts.
          max_seq_len (:obj:`int`, `optional`, defaults to 128):
              If set to a number, will limit the total sequence returned so that it has a maximum length.
          batch_size(obj:`int`, defaults to 1): The number of batch.
          use_gpu(obj:`bool`, defaults to `False`): Whether to use gpu to run or not.
      Returns:
          results(obj:`list`): All the predictions labels.
      """
      if self.task in self._tasks_supported:  # cls service
          if self.label_map:
              # compatible with json decoding label_map
              self.label_map = {
                  int(k): v for k, v in self.label_map.items()
              }
          results = self.predict(data, max_seq_len, batch_size, use_gpu)
  
          if self.task == "token-cls":
              # remove labels of [CLS] token and pad tokens
              results = [
                  token_labels[1 : len(data[i][0]) + 1]
                  for i, token_labels in enumerate(results)
              ]
          return results
      elif self.task is None:  # embedding service
          results = self.get_embedding(data, use_gpu)
          return results
      else:  # unknown service
          logger.error(
              f"Unknown task {self.task}, current tasks supported:\n"
              "1. seq-cls: sequence classification service;\n"
              "2. token-cls: sequence labeling service;\n"
              "3. None: embedding service"
          )
      return
  
imports: import copy
  import functools
  import inspect
  import io
  import json
  import os
  import six
  from typing import List, Tuple, Union
  import paddle
  import paddle.nn
  from packaging.version import Version
  from paddle.dataset.common import DATA_HOME
  from paddle.utils.download import get_path_from_url
  from paddlehub.module.module import serving, RunModule, runnable
  from paddlehub.utils.log import logger
  from paddlehub.utils.utils import reseg_token_label
  import paddlenlp
  from paddlenlp.embeddings.token_embedding import EMBEDDING_HOME, EMBEDDING_URL_ROOT
  from paddlenlp.data import JiebaTokenizer
  from paddlehub.compat.module.nlp_module import DataFormatError
label_desc: Use image node_id 1 for calling the TextServing obj's underlying member method code with example usage: obj.predict_method(data, max_seq_len, batch_size, use_gpu) and returns: results, results