class_docstr: fastNLP的数据容器。
  
  Example::
  
      from fastNLP.core.dataset import DataSet, Instance
      data = {'x': [[1, 0, 1], [0, 1, 1], 'y': [0, 1]}
      data1 = [Instance(x=[1,0,1],y=0), Instance(x=[0,1,1],y=1)]
      ds = DataSet(data)
      ds = DataSet(data1)
  
  fastNLP的 DataSet 是 key-value 存储形式， 目前支持两种初始化方式，输入 data 分别为 ``List[:class:`~fastNLP.core.dataset.Instance`]`` 和
  ``Dict[str, List[Any]]``。
  
      * 当 data 为 ``List[:class:`~fastNLP.core.dataset.Instance`]`` 时,  每个 ``Instance`` 的 field_name 需要保持一致。
        Instance 详见 :class:`~fastNLP.core.dataset.Instance` 。
      * 当 data 为 ``Dict[str, List[Any]]`` 时， 则每个 key 的 value 应该为等长的 list， 否则不同 field 的长度不一致。
  
  :param data: 初始化的内容，其只能为两种类型，分别为 ``List[:class:`~fastNLP.core.dataset.Instance`]`` 和
      ``Dict[str, List[Any]]``。
  
      * 当 data 为 ``List[:class:`~fastNLP.core.dataset.Instance`]`` 时,  每个 ``Instance`` 的 field_name 需要保持一致。
        Instance 详见 :class:`~fastNLP.core.dataset.Instance` 。
      * 当 data 为 ``Dict[str, List[Any]] 时， 则每个 key 的 value 应该为等长的 list， 否则不同 field 的长度不一致。
class_docstr_tok: ["fastNLP\u7684\u6570\u636e\u5bb9\u5668\u3002","Example",":",":","from","fastNLP.core.dataset","import","DataSet",",","Instance","data","=","{","'","x","'",":","[","[","1",",","0",",","1","]",",","[","0",",","1",",","1","]",",","'","y","'",":","[","0",",","1","]","}","data1","=","[","Instance","(","x=","[","1,0,1","]",",","y=0",")",",","Instance","(","x=","[","0,1,1","]",",","y=1",")","]","ds","=","DataSet","(","data",")","ds","=","DataSet","(","data1",")","fastNLP\u7684","DataSet","\u662f","key-value","\u5b58\u50a8\u5f62\u5f0f\uff0c","\u76ee\u524d\u652f\u6301\u4e24\u79cd\u521d\u59cb\u5316\u65b9\u5f0f\uff0c\u8f93\u5165","data","\u5206\u522b\u4e3a","``","List","[",":","class",":","`","~fastNLP.core.dataset.Instance","`","]","``","\u548c","``","Dict","[","str",",","List","[","Any","]","]","``","\u3002","*","\u5f53","data","\u4e3a","``","List","[",":","class",":","`","~fastNLP.core.dataset.Instance","`","]","``","\u65f6",",","\u6bcf\u4e2a","``","Instance","``","\u7684","field_name","\u9700\u8981\u4fdd\u6301\u4e00\u81f4\u3002","Instance","\u8be6\u89c1",":","class",":","`","~fastNLP.core.dataset.Instance","`","\u3002","*","\u5f53","data","\u4e3a","``","Dict","[","str",",","List","[","Any","]","]","``","\u65f6\uff0c","\u5219\u6bcf\u4e2a","key","\u7684","value","\u5e94\u8be5\u4e3a\u7b49\u957f\u7684","list\uff0c","\u5426\u5219\u4e0d\u540c","field","\u7684\u957f\u5ea6\u4e0d\u4e00\u81f4\u3002",":","param","data",":","\u521d\u59cb\u5316\u7684\u5185\u5bb9\uff0c\u5176\u53ea\u80fd\u4e3a\u4e24\u79cd\u7c7b\u578b\uff0c\u5206\u522b\u4e3a","``","List","[",":","class",":","`","~fastNLP.core.dataset.Instance","`","]","``","\u548c","``","Dict","[","str",",","List","[","Any","]","]","``","\u3002","*","\u5f53","data","\u4e3a","``","List","[",":","class",":","`","~fastNLP.core.dataset.Instance","`","]","``","\u65f6",",","\u6bcf\u4e2a","``","Instance","``","\u7684","field_name","\u9700\u8981\u4fdd\u6301\u4e00\u81f4\u3002","Instance","\u8be6\u89c1",":","class",":","`","~fastNLP.core.dataset.Instance","`","\u3002","*","\u5f53","data","\u4e3a","``","Dict","[","str",",","List","[","Any","]","]","\u65f6\uff0c","\u5219\u6bcf\u4e2a","key","\u7684","value","\u5e94\u8be5\u4e3a\u7b49\u957f\u7684","list\uff0c","\u5426\u5219\u4e0d\u540c","field","\u7684\u957f\u5ea6\u4e0d\u4e00\u81f4\u3002"]
docstr: 将 ``DataSet`` 中的每个 ``Instance`` 中的名为 `field_name` 的 field 传给 ``func``，并获取它的返回值。
  ``func`` 可以返回一个或多个 field 上的结果。
  
  .. note::
      ``apply_field_more`` 与 ``apply_field`` 的区别参考 :meth:`~fastNLP.core.dataset.DataSet.apply_more` 中关于 ``apply_more`` 与
      ``apply`` 区别的介绍。
  
  :param func: 对指定 field 进行处理的函数，注意其输入应为 ``instance`` 中名为 ``field_name`` 的 field 的内容；返回值为一个字典，
      key 是field 的名字，value 是对应的结果
  :param field_name: 传入 ``func`` 的 field 名称；
  :param modify_fields: 是否用结果修改 ``DataSet`` 中的 ``Field`` ， 默认为 ``True``
  :param num_proc: 使用进程的数量。
  
      .. note::
      
          由于 ``python`` 语言的特性，设置该参数后会导致相应倍数的内存增长，这可能会对您程序的执行带来一定的影响。另外，使用多进程时，
          ``func`` 函数中的打印将不会输出。
  
  :param progress_desc: 如果不为 ``None``，则会显示当前正在处理的进度条的名称；
  :param progress_bar: 显示进度条的方式，支持 ``["rich", "tqdm", None]``。
  :return: 一个字典
docstr_tok: ["\u5c06","``","DataSet","``","\u4e2d\u7684\u6bcf\u4e2a","``","Instance","``","\u4e2d\u7684\u540d\u4e3a","`","field_name","`","\u7684","field","\u4f20\u7ed9","``","func","``","\uff0c\u5e76\u83b7\u53d6\u5b83\u7684\u8fd4\u56de\u503c\u3002","``","func","``","\u53ef\u4ee5\u8fd4\u56de\u4e00\u4e2a\u6216\u591a\u4e2a","field","\u4e0a\u7684\u7ed3\u679c\u3002","..","note",":",":","``","apply_field_more","``","\u4e0e","``","apply_field","``","\u7684\u533a\u522b\u53c2\u8003",":","meth",":","`","~fastNLP.core.dataset.DataSet.apply_more","`","\u4e2d\u5173\u4e8e","``","apply_more","``","\u4e0e","``","apply","``","\u533a\u522b\u7684\u4ecb\u7ecd\u3002",":","param","func",":","\u5bf9\u6307\u5b9a","field","\u8fdb\u884c\u5904\u7406\u7684\u51fd\u6570\uff0c\u6ce8\u610f\u5176\u8f93\u5165\u5e94\u4e3a","``","instance","``","\u4e2d\u540d\u4e3a","``","field_name","``","\u7684","field","\u7684\u5185\u5bb9\uff1b\u8fd4\u56de\u503c\u4e3a\u4e00\u4e2a\u5b57\u5178\uff0c","key","\u662ffield","\u7684\u540d\u5b57\uff0cvalue","\u662f\u5bf9\u5e94\u7684\u7ed3\u679c",":","param","field_name",":","\u4f20\u5165","``","func","``","\u7684","field","\u540d\u79f0\uff1b",":","param","modify_fields",":","\u662f\u5426\u7528\u7ed3\u679c\u4fee\u6539","``","DataSet","``","\u4e2d\u7684","``","Field","``","\uff0c","\u9ed8\u8ba4\u4e3a","``","True","``",":","param","num_proc",":","\u4f7f\u7528\u8fdb\u7a0b\u7684\u6570\u91cf\u3002","..","note",":",":","\u7531\u4e8e","``","python","``","\u8bed\u8a00\u7684\u7279\u6027\uff0c\u8bbe\u7f6e\u8be5\u53c2\u6570\u540e\u4f1a\u5bfc\u81f4\u76f8\u5e94\u500d\u6570\u7684\u5185\u5b58\u589e\u957f\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bf9\u60a8\u7a0b\u5e8f\u7684\u6267\u884c\u5e26\u6765\u4e00\u5b9a\u7684\u5f71\u54cd\u3002\u53e6\u5916\uff0c\u4f7f\u7528\u591a\u8fdb\u7a0b\u65f6\uff0c","``","func","``","\u51fd\u6570\u4e2d\u7684\u6253\u5370\u5c06\u4e0d\u4f1a\u8f93\u51fa\u3002",":","param","progress_desc",":","\u5982\u679c\u4e0d\u4e3a","``","None","``","\uff0c\u5219\u4f1a\u663e\u793a\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684\u8fdb\u5ea6\u6761\u7684\u540d\u79f0\uff1b",":","param","progress_bar",":","\u663e\u793a\u8fdb\u5ea6\u6761\u7684\u65b9\u5f0f\uff0c\u652f\u6301","``","[","``","rich","''",",","``","tqdm","''",",","None","]","``","\u3002",":","return",":","\u4e00\u4e2a\u5b57\u5178"]
code: def apply_field_more(
      self,
      func: Callable = None,
      field_name: str = None,
      modify_fields: bool = True,
      num_proc: int = 0,
      progress_desc: str = None,
      progress_bar: str = "rich",
  ):
      r"""
      将 ``DataSet`` 中的每个 ``Instance`` 中的名为 `field_name` 的 field 传给 ``func``，并获取它的返回值。
      ``func`` 可以返回一个或多个 field 上的结果。
  
      .. note::
          ``apply_field_more`` 与 ``apply_field`` 的区别参考 :meth:`~fastNLP.core.dataset.DataSet.apply_more` 中关于 ``apply_more`` 与
          ``apply`` 区别的介绍。
  
      :param func: 对指定 field 进行处理的函数，注意其输入应为 ``instance`` 中名为 ``field_name`` 的 field 的内容；返回值为一个字典，
          key 是field 的名字，value 是对应的结果
      :param field_name: 传入 ``func`` 的 field 名称；
      :param modify_fields: 是否用结果修改 ``DataSet`` 中的 ``Field`` ， 默认为 ``True``
      :param num_proc: 使用进程的数量。
  
          .. note::
  
              由于 ``python`` 语言的特性，设置该参数后会导致相应倍数的内存增长，这可能会对您程序的执行带来一定的影响。另外，使用多进程时，
              ``func`` 函数中的打印将不会输出。
  
      :param progress_desc: 如果不为 ``None``，则会显示当前正在处理的进度条的名称；
      :param progress_bar: 显示进度条的方式，支持 ``["rich", "tqdm", None]``。
      :return: 一个字典
      """
      assert len(self) != 0, "Null DataSet cannot use apply_field()."
      if not self.has_field(field_name=field_name):
          raise KeyError(
              "DataSet has no field named `{}`.".format(field_name)
          )
      idx = -1
      results = {}
      apply_out = self._apply_process(
          num_proc,
          func,
          progress_desc=progress_desc,
          progress_bar=progress_bar,
          _apply_field=field_name,
      )
      #   只检测第一个数据是否为dict类型，若是则默认所有返回值为dict；否则报错。
      if not isinstance(apply_out[0], Mapping):
          raise Exception(
              f"The result of func is not a Mapping, but a {type(apply_out[0])}"
          )
  
      for key, value in apply_out[0].items():
          results[key] = [value]
      #   尝试合并所有dict数据, idx+1 的原因是第一条数据不可能出现错误，默认第一条数据为准
      try:
          for idx, per_out in enumerate(apply_out[1:]):
              if len(set(results.keys()) - set(per_out.keys())):
                  raise ApplyResultException(
                      "apply results have different fields", idx + 1
                  )
              for key, value in per_out.items():
                  results[key].append(value)
  
      except Exception as e:
          if idx != -1:
              logger.error(
                  "Exception happens at the `{}`th instance.".format(
                      idx + 1
                  )
              )
          raise e
  
      if modify_fields is True:
          for field, result in results.items():
              self.add_field(field_name=field, fields=result)
  
      return results
  
imports: import _pickle
  from copy import deepcopy
  from typing import Optional, List, Callable, Union, Dict, Any, Mapping
  from types import LambdaType
  import sys
  import time
  import numpy
  from .field import FieldArray
  from .instance import Instance
  from fastNLP.core.utils.utils import pretty_table_printer, deprecated
  from fastNLP.core.collators import Collator
  from fastNLP.core.utils.rich_progress import f_rich_progress, DummyFRichProgress
  from fastNLP.core.utils.tqdm_progress import f_tqdm_progress
  from ..log import logger
  from fastNLP.core.utils.dummy_class import DummyClass
  from ..utils.utils import _get_fun_msg
label_desc: Use image node_id 26 for calling the DataSet obj's underlying member method code with example usage: obj.apply_field_more(func, field_name, modify_fields, num_proc, progress_desc, progress_bar) and returns: results