docstr: ERNIE 3.0 Zeus 自定义接口
  
  Params:
      text(srt): 模型的输入文本, 为 prompt 形式的输入。文本长度 [1, 1000]。注: ERNIE 3.0-1.5B 模型取值范围 ≤ 512。
      min_dec_len(int): 输出结果的最小长度, 避免因模型生成 END 或者遇到用户指定的 stop_token 而生成长度过短的情况,与 seq_len 结合使用来设置生成文本的长度范围 [1, seq_len]。
      seq_len(int): 输出结果的最大长度, 因模型生成 END 或者遇到用户指定的 stop_token, 实际返回结果可能会小于这个长度, 与 min_dec_len 结合使用来控制生成文本的长度范围 [1, 1000]。(注: ERNIE 3.0-1.5B 模型取值范围 ≤ 512)
      topp(float): 影响输出文本的多样性, 取值越大, 生成文本的多样性越强。取值范围 [0.0, 1.0]。
      penalty_score(float): 通过对已生成的 token 增加惩罚, 减少重复生成的现象。值越大表示惩罚越大。取值范围 [1.0, 2.0]。
      stop_token(str): 预测结果解析时使用的结束字符串, 碰到对应字符串则直接截断并返回。可以通过设置该值, 过滤掉 few-shot 等场景下模型重复的 cases。
      task_prompt(str): 指定预置的任务模板, 效果更好。
                        PARAGRAPH: 引导模型生成一段文章; SENT: 引导模型生成一句话; ENTITY: 引导模型生成词组;
                        Summarization: 摘要; MT: 翻译; Text2Annotation: 抽取; Correction: 纠错;
                        QA_MRC: 阅读理解; Dialogue: 对话; QA_Closed_book: 闭卷问答; QA_Multi_Choice: 多选问答;
                        QuestionGeneration: 问题生成; Paraphrasing: 复述; NLI: 文本蕴含识别; SemanticMatching: 匹配;
                        Text2SQL: 文本描述转SQL; TextClassification: 文本分类; SentimentClassification: 情感分析;
                        zuowen: 写作文; adtext: 写文案; couplet: 对对联; novel: 写小说; cloze: 文本补全; Misc: 其它任务。
      penalty_text(str): 模型会惩罚该字符串中的 token。通过设置该值, 可以减少某些冗余与异常字符的生成。
      choice_text(str): 模型只能生成该字符串中的 token 的组合。通过设置该值, 可以对某些抽取式任务进行定向调优。
      is_unidirectional(bool): False 表示模型为双向生成, True 表示模型为单向生成。建议续写与 few-shot 等通用场景建议采用单向生成方式, 而完型填空等任务相关场景建议采用双向生成方式。
      min_dec_penalty_text(str): 与最小生成长度搭配使用, 可以在 min_dec_len 步前不让模型生成该字符串中的 tokens。
      logits_bias(int): 配合 penalty_text 使用, 对给定的 penalty_text 中的 token 增加一个 logits_bias, 可以通过设置该值屏蔽某些 token 生成的概率。
      mask_type(str): 设置该值可以控制模型生成粒度。可选参数为 word, sentence, paragraph。
  
  Return:
      text(str): 生成的文本
docstr_tok: ["ERNIE","3.0","Zeus","\u81ea\u5b9a\u4e49\u63a5\u53e3","Params",":","text","(","srt",")",":","\u6a21\u578b\u7684\u8f93\u5165\u6587\u672c",",","\u4e3a","prompt","\u5f62\u5f0f\u7684\u8f93\u5165\u3002\u6587\u672c\u957f\u5ea6","[","1",",","1000","]","\u3002\u6ce8",":","ERNIE","3.0-1.5B","\u6a21\u578b\u53d6\u503c\u8303\u56f4","\u2264","512\u3002","min_dec_len","(","int",")",":","\u8f93\u51fa\u7ed3\u679c\u7684\u6700\u5c0f\u957f\u5ea6",",","\u907f\u514d\u56e0\u6a21\u578b\u751f\u6210","END","\u6216\u8005\u9047\u5230\u7528\u6237\u6307\u5b9a\u7684","stop_token","\u800c\u751f\u6210\u957f\u5ea6\u8fc7\u77ed\u7684\u60c5\u51b5",",","\u4e0e","seq_len","\u7ed3\u5408\u4f7f\u7528\u6765\u8bbe\u7f6e\u751f\u6210\u6587\u672c\u7684\u957f\u5ea6\u8303\u56f4","[","1",",","seq_len","]","\u3002","seq_len","(","int",")",":","\u8f93\u51fa\u7ed3\u679c\u7684\u6700\u5927\u957f\u5ea6",",","\u56e0\u6a21\u578b\u751f\u6210","END","\u6216\u8005\u9047\u5230\u7528\u6237\u6307\u5b9a\u7684","stop_token",",","\u5b9e\u9645\u8fd4\u56de\u7ed3\u679c\u53ef\u80fd\u4f1a\u5c0f\u4e8e\u8fd9\u4e2a\u957f\u5ea6",",","\u4e0e","min_dec_len","\u7ed3\u5408\u4f7f\u7528\u6765\u63a7\u5236\u751f\u6210\u6587\u672c\u7684\u957f\u5ea6\u8303\u56f4","[","1",",","1000","]","\u3002","(","\u6ce8",":","ERNIE","3.0-1.5B","\u6a21\u578b\u53d6\u503c\u8303\u56f4","\u2264","512",")","topp","(","float",")",":","\u5f71\u54cd\u8f93\u51fa\u6587\u672c\u7684\u591a\u6837\u6027",",","\u53d6\u503c\u8d8a\u5927",",","\u751f\u6210\u6587\u672c\u7684\u591a\u6837\u6027\u8d8a\u5f3a\u3002\u53d6\u503c\u8303\u56f4","[","0.0",",","1.0","]","\u3002","penalty_score","(","float",")",":","\u901a\u8fc7\u5bf9\u5df2\u751f\u6210\u7684","token","\u589e\u52a0\u60e9\u7f5a",",","\u51cf\u5c11\u91cd\u590d\u751f\u6210\u7684\u73b0\u8c61\u3002\u503c\u8d8a\u5927\u8868\u793a\u60e9\u7f5a\u8d8a\u5927\u3002\u53d6\u503c\u8303\u56f4","[","1.0",",","2.0","]","\u3002","stop_token","(","str",")",":","\u9884\u6d4b\u7ed3\u679c\u89e3\u6790\u65f6\u4f7f\u7528\u7684\u7ed3\u675f\u5b57\u7b26\u4e32",",","\u78b0\u5230\u5bf9\u5e94\u5b57\u7b26\u4e32\u5219\u76f4\u63a5\u622a\u65ad\u5e76\u8fd4\u56de\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u8be5\u503c",",","\u8fc7\u6ee4\u6389","few-shot","\u7b49\u573a\u666f\u4e0b\u6a21\u578b\u91cd\u590d\u7684","cases\u3002","task_prompt","(","str",")",":","\u6307\u5b9a\u9884\u7f6e\u7684\u4efb\u52a1\u6a21\u677f",",","\u6548\u679c\u66f4\u597d\u3002","PARAGRAPH",":","\u5f15\u5bfc\u6a21\u578b\u751f\u6210\u4e00\u6bb5\u6587\u7ae0",";","SENT",":","\u5f15\u5bfc\u6a21\u578b\u751f\u6210\u4e00\u53e5\u8bdd",";","ENTITY",":","\u5f15\u5bfc\u6a21\u578b\u751f\u6210\u8bcd\u7ec4",";","Summarization",":","\u6458\u8981",";","MT",":","\u7ffb\u8bd1",";","Text2Annotation",":","\u62bd\u53d6",";","Correction",":","\u7ea0\u9519",";","QA_MRC",":","\u9605\u8bfb\u7406\u89e3",";","Dialogue",":","\u5bf9\u8bdd",";","QA_Closed_book",":","\u95ed\u5377\u95ee\u7b54",";","QA_Multi_Choice",":","\u591a\u9009\u95ee\u7b54",";","QuestionGeneration",":","\u95ee\u9898\u751f\u6210",";","Paraphrasing",":","\u590d\u8ff0",";","NLI",":","\u6587\u672c\u8574\u542b\u8bc6\u522b",";","SemanticMatching",":","\u5339\u914d",";","Text2SQL",":","\u6587\u672c\u63cf\u8ff0\u8f6cSQL",";","TextClassification",":","\u6587\u672c\u5206\u7c7b",";","SentimentClassification",":","\u60c5\u611f\u5206\u6790",";","zuowen",":","\u5199\u4f5c\u6587",";","adtext",":","\u5199\u6587\u6848",";","couplet",":","\u5bf9\u5bf9\u8054",";","novel",":","\u5199\u5c0f\u8bf4",";","cloze",":","\u6587\u672c\u8865\u5168",";","Misc",":","\u5176\u5b83\u4efb\u52a1\u3002","penalty_text","(","str",")",":","\u6a21\u578b\u4f1a\u60e9\u7f5a\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684","token\u3002\u901a\u8fc7\u8bbe\u7f6e\u8be5\u503c",",","\u53ef\u4ee5\u51cf\u5c11\u67d0\u4e9b\u5197\u4f59\u4e0e\u5f02\u5e38\u5b57\u7b26\u7684\u751f\u6210\u3002","choice_text","(","str",")",":","\u6a21\u578b\u53ea\u80fd\u751f\u6210\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684","token","\u7684\u7ec4\u5408\u3002\u901a\u8fc7\u8bbe\u7f6e\u8be5\u503c",",","\u53ef\u4ee5\u5bf9\u67d0\u4e9b\u62bd\u53d6\u5f0f\u4efb\u52a1\u8fdb\u884c\u5b9a\u5411\u8c03\u4f18\u3002","is_unidirectional","(","bool",")",":","False","\u8868\u793a\u6a21\u578b\u4e3a\u53cc\u5411\u751f\u6210",",","True","\u8868\u793a\u6a21\u578b\u4e3a\u5355\u5411\u751f\u6210\u3002\u5efa\u8bae\u7eed\u5199\u4e0e","few-shot","\u7b49\u901a\u7528\u573a\u666f\u5efa\u8bae\u91c7\u7528\u5355\u5411\u751f\u6210\u65b9\u5f0f",",","\u800c\u5b8c\u578b\u586b\u7a7a\u7b49\u4efb\u52a1\u76f8\u5173\u573a\u666f\u5efa\u8bae\u91c7\u7528\u53cc\u5411\u751f\u6210\u65b9\u5f0f\u3002","min_dec_penalty_text","(","str",")",":","\u4e0e\u6700\u5c0f\u751f\u6210\u957f\u5ea6\u642d\u914d\u4f7f\u7528",",","\u53ef\u4ee5\u5728","min_dec_len","\u6b65\u524d\u4e0d\u8ba9\u6a21\u578b\u751f\u6210\u8be5\u5b57\u7b26\u4e32\u4e2d\u7684","tokens\u3002","logits_bias","(","int",")",":","\u914d\u5408","penalty_text","\u4f7f\u7528",",","\u5bf9\u7ed9\u5b9a\u7684","penalty_text","\u4e2d\u7684","token","\u589e\u52a0\u4e00\u4e2a","logits_bias",",","\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u8be5\u503c\u5c4f\u853d\u67d0\u4e9b","token","\u751f\u6210\u7684\u6982\u7387\u3002","mask_type","(","str",")",":","\u8bbe\u7f6e\u8be5\u503c\u53ef\u4ee5\u63a7\u5236\u6a21\u578b\u751f\u6210\u7c92\u5ea6\u3002\u53ef\u9009\u53c2\u6570\u4e3a","word",",","sentence",",","paragraph\u3002","Return",":","text","(","str",")",":","\u751f\u6210\u7684\u6587\u672c"]
code: def custom_generation(
      self,
      text: str,
      min_dec_len: int = 1,
      seq_len: int = 128,
      topp: float = 1.0,
      penalty_score: float = 1.0,
      stop_token: str = "",
      task_prompt: str = "",
      penalty_text: str = "",
      choice_text: str = "",
      is_unidirectional: bool = False,
      min_dec_penalty_text: str = "",
      logits_bias: int = -10000,
      mask_type: str = "word",
  ) -> str:
      """
      ERNIE 3.0 Zeus 自定义接口
  
      Params:
          text(srt): 模型的输入文本, 为 prompt 形式的输入。文本长度 [1, 1000]。注: ERNIE 3.0-1.5B 模型取值范围 ≤ 512。
          min_dec_len(int): 输出结果的最小长度, 避免因模型生成 END 或者遇到用户指定的 stop_token 而生成长度过短的情况,与 seq_len 结合使用来设置生成文本的长度范围 [1, seq_len]。
          seq_len(int): 输出结果的最大长度, 因模型生成 END 或者遇到用户指定的 stop_token, 实际返回结果可能会小于这个长度, 与 min_dec_len 结合使用来控制生成文本的长度范围 [1, 1000]。(注: ERNIE 3.0-1.5B 模型取值范围 ≤ 512)
          topp(float): 影响输出文本的多样性, 取值越大, 生成文本的多样性越强。取值范围 [0.0, 1.0]。
          penalty_score(float): 通过对已生成的 token 增加惩罚, 减少重复生成的现象。值越大表示惩罚越大。取值范围 [1.0, 2.0]。
          stop_token(str): 预测结果解析时使用的结束字符串, 碰到对应字符串则直接截断并返回。可以通过设置该值, 过滤掉 few-shot 等场景下模型重复的 cases。
          task_prompt(str): 指定预置的任务模板, 效果更好。
                            PARAGRAPH: 引导模型生成一段文章; SENT: 引导模型生成一句话; ENTITY: 引导模型生成词组;
                            Summarization: 摘要; MT: 翻译; Text2Annotation: 抽取; Correction: 纠错;
                            QA_MRC: 阅读理解; Dialogue: 对话; QA_Closed_book: 闭卷问答; QA_Multi_Choice: 多选问答;
                            QuestionGeneration: 问题生成; Paraphrasing: 复述; NLI: 文本蕴含识别; SemanticMatching: 匹配;
                            Text2SQL: 文本描述转SQL; TextClassification: 文本分类; SentimentClassification: 情感分析;
                            zuowen: 写作文; adtext: 写文案; couplet: 对对联; novel: 写小说; cloze: 文本补全; Misc: 其它任务。
          penalty_text(str): 模型会惩罚该字符串中的 token。通过设置该值, 可以减少某些冗余与异常字符的生成。
          choice_text(str): 模型只能生成该字符串中的 token 的组合。通过设置该值, 可以对某些抽取式任务进行定向调优。
          is_unidirectional(bool): False 表示模型为双向生成, True 表示模型为单向生成。建议续写与 few-shot 等通用场景建议采用单向生成方式, 而完型填空等任务相关场景建议采用双向生成方式。
          min_dec_penalty_text(str): 与最小生成长度搭配使用, 可以在 min_dec_len 步前不让模型生成该字符串中的 tokens。
          logits_bias(int): 配合 penalty_text 使用, 对给定的 penalty_text 中的 token 增加一个 logits_bias, 可以通过设置该值屏蔽某些 token 生成的概率。
          mask_type(str): 设置该值可以控制模型生成粒度。可选参数为 word, sentence, paragraph。
  
      Return:
          text(str): 生成的文本
      """
      url = "https://wenxin.baidu.com/moduleApi/portal/api/rest/1.0/ernie/3.0.28/zeus?from=paddlehub"
      access_token = self.access_token
      headers = {"Content-Type": "application/x-www-form-urlencoded"}
      datas = {
          "access_token": access_token,
          "text": text,
          "min_dec_len": min_dec_len,
          "seq_len": seq_len,
          "topp": topp,
          "penalty_score": penalty_score,
          "stop_token": stop_token,
          "task_prompt": task_prompt,
          "penalty_text": penalty_text,
          "choice_text": choice_text,
          "is_unidirectional": int(is_unidirectional),
          "min_dec_penalty_text": min_dec_penalty_text,
          "logits_bias": logits_bias,
          "mask_type": mask_type,
      }
  
      responses = requests.post(url, datas, headers=headers)
  
      assert (
          responses.status_code == 200
      ), f"Network Error {responses.status_code}."
  
      results = json.loads(responses.text)
  
      assert results["code"] == 0, f"Error message: '{results['msg']}'."
  
      return results["data"]["result"]
  
imports: import argparse
  import json
  import os
  import requests
  from paddlehub.module.module import moduleinfo
  from paddlehub.module.module import runnable
  from paddlehub.module.module import serving
label_desc: Use image node_id 2 for calling the ERNIEZeus obj's underlying member method code with example usage: obj.custom_generation(text, min_dec_len, seq_len, topp, penalty_score, stop_token, task_prompt, penalty_text, choice_text, is_unidirectional, min_dec_penalty_text, logits_bias, mask_type) and returns: results