fastNLP.io

用于IO的模块, 具体包括:

  1. 用于读入 embedding 的 EmbedLoader 类,

  2. 用于读入不同格式数据的 Loader

  3. 用于处理读入数据的 Pipe

  4. 用于保存和载入模型的类, 参考 model_io模块

这些类的使用方法如下:

class fastNLP.io.DataBundle(vocabs: dict = None, datasets: dict = None)[源代码]

别名 fastNLP.io.DataBundle fastNLP.io.data_bundle.DataBundle

经过处理的数据信息,包括一系列数据集(比如:分开的训练集、验证集和测试集)以及各个field对应的vocabulary。该对象一般由fastNLP中各种 Loader的load函数生成,可以通过以下的方法获取里面的内容

Example:

data_bundle = YelpLoader().load({'train':'/path/to/train', 'dev': '/path/to/dev'})
train_vocabs = data_bundle.vocabs['train']
train_data = data_bundle.datasets['train']
dev_data = data_bundle.datasets['train']
__init__(vocabs: dict = None, datasets: dict = None)[源代码]
参数
  • vocabs -- 从名称(字符串)到 Vocabulary 类型的dict

  • datasets -- 从名称(字符串)到 DataSet 类型的dict。建议不要将相同的DataSet对象重复传入,可能会在 使用Pipe处理数据的时候遇到问题,若多个数据集确需一致,请手动deepcopy后传入。

set_vocab(vocab, field_name)[源代码]

向DataBunlde中增加vocab

参数
  • vocab (Vocabulary) -- 词表

  • field_name (str) -- 这个vocab对应的field名称

返回

self

set_dataset(dataset, name: str)[源代码]
参数
  • dataset (DataSet) -- 传递给DataBundle的DataSet

  • name (str) -- dataset的名称

返回

self

get_dataset(name: str)fastNLP.core.dataset.DataSet[源代码]

获取名为name的dataset

参数

name (str) -- dataset的名称,一般为'train', 'dev', 'test'

返回

DataSet

delete_dataset(name: str)[源代码]

删除名为name的DataSet

参数

name (str) --

返回

self

get_vocab(field_name: str)fastNLP.core.vocabulary.Vocabulary[源代码]

获取field名为field_name对应的vocab

参数

field_name (str) -- 名称

返回

Vocabulary

delete_vocab(field_name: str)[源代码]

删除vocab :param str field_name: :return: self

set_input(*field_names, flag=True, use_1st_ins_infer_dim_type=True, ignore_miss_dataset=True)[源代码]

将field_names中的field设置为input, 对data_bundle中所有的dataset执行该操作:

data_bundle.set_input('words', 'seq_len')   # 将words和seq_len这两个field的input属性设置为True
data_bundle.set_input('words', flag=False)  # 将words这个field的input属性设置为False
参数
  • field_names (str) -- field的名称

  • flag (bool) -- 将field_name的input状态设置为flag

  • use_1st_ins_infer_dim_type (bool) -- 如果为True,将不会check该列是否所有数据都是同样的维度,同样的类型。将直接使用第一 行的数据进行类型和维度推断本列的数据的类型和维度。

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

返回

self

set_target(*field_names, flag=True, use_1st_ins_infer_dim_type=True, ignore_miss_dataset=True)[源代码]

将field_names中的field设置为target, 对data_bundle中所有的dataset执行该操作:

data_bundle.set_target('target', 'seq_len')   # 将words和target这两个field的input属性设置为True
data_bundle.set_target('target', flag=False)  # 将target这个field的input属性设置为False
参数
  • field_names (str) -- field的名称

  • flag (bool) -- 将field_name的target状态设置为flag

  • use_1st_ins_infer_dim_type (bool) -- 如果为True,将不会check该列是否所有数据都是同样的维度,同样的类型。将直接使用第一 行的数据进行类型和维度推断本列的数据的类型和维度。

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

返回

self

set_pad_val(field_name, pad_val, ignore_miss_dataset=True)[源代码]

将DataBundle中所有的DataSet中名为field_name的Field的padding值设置为pad_val.

参数
  • field_name (str) --

  • pad_val (int) --

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

返回

self

set_ignore_type(*field_names, flag=True, ignore_miss_dataset=True)[源代码]

将DataBundle中所有的DataSet中名为*field_names的Field的ignore_type设置为flag状态

参数
  • field_names (str) --

  • flag (bool) --

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

返回

self

copy_field(field_name, new_field_name, ignore_miss_dataset=True)[源代码]

将DataBundle中所有的DataSet中名为field_name的Field复制一份并命名为叫new_field_name.

参数
  • field_name (str) --

  • new_field_name (str) --

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

返回

self

rename_field(field_name, new_field_name, ignore_miss_dataset=True, rename_vocab=True)[源代码]

将DataBundle中所有DataSet中名为field_name的field重命名为new_field_name.

参数
  • field_name (str) --

  • new_field_name (str) --

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

  • rename_vocab (bool) -- 如果该field同时也存在于vocabs中,会将该field的名称对应修改

返回

self

delete_field(field_name, ignore_miss_dataset=True, delete_vocab=True)[源代码]

将DataBundle中所有DataSet中名为field_name的field删除掉.

参数
  • field_name (str) --

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

  • delete_vocab (bool) -- 如果该field也在vocabs中存在,将该值也一并删除

返回

self

iter_datasets() → Union[str, fastNLP.core.dataset.DataSet][源代码]

迭代data_bundle中的DataSet

Example:

for name, dataset in data_bundle.iter_datasets():
    pass
返回

get_dataset_names() → List[str][源代码]

返回DataBundle中DataSet的名称

返回

get_vocab_names() → List[str][源代码]

返回DataBundle中Vocabulary的名称

返回

iter_vocabs() → Union[str, fastNLP.core.vocabulary.Vocabulary][源代码]

迭代data_bundle中的DataSet

Example:

for field_name, vocab in data_bundle.iter_vocabs():

pass

返回

apply_field(func, field_name: str, new_field_name: str, ignore_miss_dataset=True, **kwargs)[源代码]

DataBundle 中所有的dataset使用 apply_field() 方法

参数
  • func (callable) -- input是instance中名为 field_name 的field的内容。

  • field_name (str) -- 传入func的是哪个field。

  • new_field_name (str) -- 将func返回的内容放入到 new_field_name 这个field中,如果名称与已有的field相同,则覆 盖之前的field。如果为None则不创建新的field。

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

  • kwargs (optional) --

    支持输入is_input,is_target,ignore_type

    1. is_input: bool, 如果为True则将名为 new_field_name 的field设置为input

    2. is_target: bool, 如果为True则将名为 new_field_name 的field设置为target

    3. ignore_type: bool, 如果为True则将名为 new_field_name 的field的ignore_type设置为true, 忽略其类型

    4. use_tqdm: bool, 是否显示tqdm进度条

    5. tqdm_desc: str, 当use_tqdm为True时,可以显示当前tqdm正在处理的名称

apply_field_more(func, field_name, modify_fields=True, ignore_miss_dataset=True, **kwargs)[源代码]

DataBundle 中所有的 dataset 使用 apply_field_more() 方法

注解

apply_field_moreapply_field 的区别参考 fastNLP.DataSet.apply_more() 中关于 apply_moreapply 区别的介绍。

参数
  • func (callable) -- 参数是 DataSet 中的 Instance ,返回值是一个字典,key 是field 的名字,value 是对应的结果

  • field_name (str) -- 传入func的是哪个field。

  • modify_fields (bool) -- 是否用结果修改 DataSet 中的 Field, 默认为 True

  • ignore_miss_dataset (bool) -- 当某个field名称在某个dataset不存在时,如果为True,则直接忽略该DataSet; 如果为False,则报错

  • kwargs (optional) --

    支持输入is_input, is_target, ignore_type

    1. is_input: bool, 如果为True则将被修改的field设置为input

    2. is_target: bool, 如果为True则将被修改的field设置为target

    3. ignore_type: bool, 如果为True则将被修改的field的ignore_type设置为true, 忽略其类型

    4. use_tqdm: bool, 是否显示tqdm进度条

    5. tqdm_desc: str, 当use_tqdm为True时,可以显示当前tqdm正在处理的名称

Return Dict[str:Dict[str:Field]]

返回一个字典套字典,第一层的 key 是 dataset 的名字,第二层的 key 是 field 的名字

apply(func, new_field_name: str, **kwargs)[源代码]

DataBundle 中所有的 dataset 使用 apply() 方法

对DataBundle中所有的dataset使用apply方法

参数
  • func (callable) -- input是instance中名为 field_name 的field的内容。

  • new_field_name (str) -- 将func返回的内容放入到 new_field_name 这个field中,如果名称与已有的field相同,则覆 盖之前的field。如果为None则不创建新的field。

  • kwargs (optional) --

    支持输入is_input,is_target,ignore_type

    1. is_input: bool, 如果为True则将名为 new_field_name 的field设置为input

    2. is_target: bool, 如果为True则将名为 new_field_name 的field设置为target

    3. ignore_type: bool, 如果为True则将名为 new_field_name 的field的ignore_type设置为true, 忽略其类型

    4. use_tqdm: bool, 是否显示tqdm进度条

    5. tqdm_desc: str, 当use_tqdm为True时,可以显示当前tqdm正在处理的名称

apply_more(func, modify_fields=True, **kwargs)[源代码]

DataBundle 中所有的 dataset 使用 apply_more() 方法

注解

apply_moreapply 的区别参考 fastNLP.DataSet.apply_more() 中关于 apply_moreapply 区别的介绍。

参数
  • func (callable) -- 参数是 DataSet 中的 Instance ,返回值是一个字典,key 是field 的名字,value 是对应的结果

  • modify_fields (bool) -- 是否用结果修改 DataSet 中的 Field , 默认为 True

  • kwargs (optional) --

    支持输入is_input,is_target,ignore_type

    1. is_input: bool, 如果为True则将被修改的的field设置为input

    2. is_target: bool, 如果为True则将被修改的的field设置为target

    3. ignore_type: bool, 如果为True则将被修改的的field的ignore_type设置为true, 忽略其类型

    4. use_tqdm: bool, 是否显示tqdm进度条

    5. tqdm_desc: str, 当use_tqdm为True时,可以显示当前tqdm正在处理的名称

Return Dict[str:Dict[str:Field]]

返回一个字典套字典,第一层的 key 是 dataset 的名字,第二层的 key 是 field 的名字

add_collate_fn(fn, name=None)[源代码]

向所有DataSet增加collate_fn, collate_fn详见 DataSet 中相关说明.

参数
  • fn (callable) --

  • name --

返回

delete_collate_fn(name=None)[源代码]

删除DataSet中的collate_fn

参数

name --

返回

class fastNLP.io.EmbedLoader[源代码]

别名 fastNLP.io.EmbedLoader fastNLP.io.embed_loader.EmbedLoader

用于读取预训练的embedding, 读取结果可直接载入为模型参数。

static load_with_vocab(embed_filepath, vocab, dtype=<class 'numpy.float32'>, padding='<pad>', unknown='<unk>', normalize=True, error='ignore', init_method=None)[源代码]

从embed_filepath这个预训练的词向量中抽取出vocab这个词表的词的embedding。EmbedLoader将自动判断embed_filepath是 word2vec(第一行只有两个元素)还是glove格式的数据。

参数
  • embed_filepath (str) -- 预训练的embedding的路径。

  • vocab -- 词表 Vocabulary 类型,读取出现在vocab中的词的embedding。 没有出现在vocab中的词的embedding将通过找到的词的embedding的正态分布采样出来,以使得整个Embedding是同分布的。

  • dtype -- 读出的embedding的类型

  • padding (str) -- 词表中padding的token

  • unknown (str) -- 词表中unknown的token

  • normalize (bool) -- 是否将每个vector归一化到norm为1

  • error (str) -- ignore , strict ; 如果 ignore ,错误将自动跳过; 如果 strict , 错误将抛出。 这里主要可能出错的地方在于词表有空行或者词表出现了维度不一致。

  • init_method (callable) -- 传入numpy.ndarray, 返回numpy.ndarray, 用以初始化embedding

Return numpy.ndarray

shape为 [len(vocab), dimension], dimension由pretrain的embedding决定。

static load_without_vocab(embed_filepath, dtype=<class 'numpy.float32'>, padding='<pad>', unknown='<unk>', normalize=True, error='ignore')[源代码]

从embed_filepath中读取预训练的word vector。根据预训练的词表读取embedding并生成一个对应的Vocabulary。

参数
  • embed_filepath (str) -- 预训练的embedding的路径。

  • dtype -- 读出的embedding的类型

  • padding (str) -- 词表中的padding的token. 并以此用做vocab的padding。

  • unknown (str) -- 词表中的unknown的token. 并以此用做vocab的unknown。

  • normalize (bool) -- 是否将每个vector归一化到norm为1

  • error (str) -- ignore , strict ; 如果 ignore ,错误将自动跳过; 如果 strict , 错误将抛出。这里主要可能出错的地 方在于词表有空行或者词表出现了维度不一致。

Return (numpy.ndarray, Vocabulary)

Embedding的shape是[词表大小+x, 词表维度], "词表大小+x"是由于最终的大小还取决与 是否使用padding, 以及unknown有没有在词表中找到对应的词。 Vocabulary中的词的顺序与Embedding的顺序是一一对应的。

class fastNLP.io.Loader[源代码]

别名 fastNLP.io.Loader fastNLP.io.loader.Loader

各种数据 Loader 的基类,提供了 API 的参考. Loader支持以下的三个函数

  • download() 函数:自动将该数据集下载到缓存地址,默认缓存地址为~/.fastNLP/datasets/。由于版权等原因,不是所有的Loader都实现了该方法。该方法会返回下载后文件所处的缓存地址。

  • _load() 函数:从一个数据文件中读取数据,返回一个 DataSet 。返回的DataSet的内容可以通过每个Loader的文档判断出。

  • load() 函数:将文件分别读取为DataSet,然后将多个DataSet放入到一个DataBundle中并返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle[源代码]

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

download() → str[源代码]

自动下载该数据集

返回

下载后解压目录

class fastNLP.io.CLSBaseLoader(sep=',', has_header=False)[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.CLSBaseLoader fastNLP.io.loader.CLSBaseLoader

文本分类Loader的一个基类

原始数据中内容应该为, 每一行为一个sample,第一个逗号之前为target,第一个逗号之后为文本内容。

Example:

"1","I got 'new' tires from the..."
"1","Don't waste your time..."

读取的DataSet将具备以下的数据结构

raw_words

target

I got 'new' tires from them and...

1

Don't waste your time. We had two...

1

...

...

download() → str

自动下载该数据集

返回

下载后解压目录

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.IMDBLoader[源代码]

基类 fastNLP.io.CLSBaseLoader

别名 fastNLP.io.IMDBLoader fastNLP.io.loader.IMDBLoader

原始数据中内容应该为, 每一行为一个sample,制表符之前为target,制表符之后为文本内容。

Example:

neg     Alan Rickman & Emma...
neg     I have seen this...

IMDBLoader读取后的数据将具有以下两列内容: raw_words: str, 需要分类的文本; target: str, 文本的标签 读取的DataSet具备以下的结构:

raw_words

target

Alan Rickman & Emma...

neg

I have seen this...

neg

...

...

download(dev_ratio: float = 0.0, re_download=False)[源代码]

自动下载数据集,如果你使用了这个数据集,请引用以下的文章

http://www.aclweb.org/anthology/P11-1015

根据dev_ratio的值随机将train中的数据取出一部分作为dev数据。下载完成后不从train中切分dev

参数
  • dev_ratio (float) -- 如果路径中没有dev.txt。从train划分多少作为dev的数据. 如果为0,则不划分dev

  • re_download (bool) -- 是否重新下载数据,以重新切分数据。

返回

str, 数据集的目录地址

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.SSTLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.SSTLoader fastNLP.io.loader.SSTLoader

原始数据中内容应该为:

Example:

(2 (3 (3 Effective) (2 but)) (1 (1 too-tepid)...
(3 (3 (2 If) (3 (2 you) (3 (2 sometimes)...

读取之后的DataSet具有以下的结构

下面是使用SSTLoader读取的DataSet所具备的field

raw_words

(2 (3 (3 Effective) (2 but)) (1 (1 too-tepid)...

(3 (3 (2 If) (3 (2 you) (3 (2 sometimes) ...

...

raw_words列是str。

download()[源代码]

自动下载数据集,如果你使用了这个数据集,请引用以下的文章

返回

str, 数据集的目录地址

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.SST2Loader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.SST2Loader fastNLP.io.loader.SST2Loader

原始数据中内容为:第一行为标题(具体内容会被忽略),之后一行为一个sample,第一个制表符之前被认为是句子,第一个制表符之后认为是label

Example:

sentence        label
it 's a charming and often affecting journey .  1
unflinchingly bleak and desperate       0

读取之后DataSet将如下所示

raw_words

target

it 's a charming and often affecting journey .

1

unflinchingly bleak and desperate

0

...

test的DataSet没有target列。

download()[源代码]

自动下载数据集,如果你使用了该数据集,请引用以下的文章 https://nlp.stanford.edu/pubs/SocherBauerManningNg_ACL2013.pdf :return:

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.ChnSentiCorpLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.ChnSentiCorpLoader fastNLP.io.loader.ChnSentiCorpLoader

支持读取的数据的格式为,第一行为标题(具体内容会被忽略),之后一行为一个sample,第一个制表符之前被认为是label,第 一个制表符之后认为是句子

Example:

label   text_a
1       基金痛所有投资项目一样,必须先要有所了解...
1       系统很好装,LED屏是不错,就是16比9的比例...

读取后的DataSet具有以下的field

raw_chars

target

基金痛所有投资项目一样,必须先要有所了解...

1

系统很好装,LED屏是不错,就是16比9的比例...

1

...

download() → str[源代码]

自动下载数据,该数据取自https://github.com/pengming617/bert_classification/tree/master/data,在 https://arxiv.org/pdf/1904.09223.pdf与https://arxiv.org/pdf/1906.08101.pdf有使用

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.THUCNewsLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.THUCNewsLoader fastNLP.io.loader.THUCNewsLoader

数据集简介:document-level分类任务,新闻10分类 原始数据内容为:每行一个sample,第一个 "\t" 之前为target,第一个 "\t" 之后为raw_words

Example:

体育      调查-您如何评价热火客场胜绿军总分3-1夺赛点?...

读取后的Dataset将具有以下数据结构:

raw_words

target

调查-您如何评价热火客场胜绿军总分3-1夺赛点?...

体育

...

...

download() → str[源代码]

自动下载数据,该数据取自

http://thuctc.thunlp.org/#%E4%B8%AD%E6%96%87%E6%96%87%E6%9C%AC%E5%88%86%E7%B1%BB%E6%95%B0%E6%8D%AE%E9%9B%86THUCNews

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.WeiboSenti100kLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.WeiboSenti100kLoader fastNLP.io.loader.WeiboSenti100kLoader

别名: 数据集简介:微博sentiment classification,二分类

Example:

label   text
1       多谢小莲,好运满满[爱你]
1       能在他乡遇老友真不赖,哈哈,珠儿,我也要用...

读取后的Dataset将具有以下数据结构:

raw_chars

target

多谢小莲,好运满满[爱你]

1

能在他乡遇老友真不赖,哈哈,珠儿,我也要用...

1

...

...

download() → str[源代码]

自动下载数据,该数据取自 https://github.com/SophonPlus/ChineseNlpCorpus/https://arxiv.org/abs/1906.08101 有使用 :return:

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.ConllLoader(headers, sep=None, indexes=None, dropna=True)[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.ConllLoader fastNLP.io.loader.ConllLoader

ConllLoader支持读取的数据格式: 以空行隔开两个sample,除了分割行,每一行用空格或者制表符隔开不同的元素。如下例所示:

Example:

# 文件中的内容
Nadim NNP B-NP B-PER
Ladki NNP I-NP I-PER

AL-AIN NNP B-NP B-LOC
United NNP B-NP B-LOC
Arab NNP I-NP I-LOC
Emirates NNPS I-NP I-LOC
1996-12-06 CD I-NP O
...

# 如果用以下的参数读取,返回的DataSet将包含raw_words和pos两个field, 这两个field的值分别取自于第0列与第1列
dataset = ConllLoader(headers=['raw_words', 'pos'], indexes=[0, 1])._load('/path/to/train.conll')
# 如果用以下的参数读取,返回的DataSet将包含raw_words和ner两个field, 这两个field的值分别取自于第0列与第2列
dataset = ConllLoader(headers=['raw_words', 'ner'], indexes=[0, 3])._load('/path/to/train.conll')
# 如果用以下的参数读取,返回的DataSet将包含raw_words, pos和ner三个field
dataset = ConllLoader(headers=['raw_words', 'pos', 'ner'], indexes=[0, 1, 3])._load('/path/to/train.conll')

ConllLoader返回的DataSet的field由传入的headers确定。

数据中以"-DOCSTART-"开头的行将被忽略,因为该符号在conll 2003中被用为文档分割符。

__init__(headers, sep=None, indexes=None, dropna=True)[源代码]
参数
  • headers (list) -- 每一列数据的名称,需为List or Tuple of str。headerindexes 一一对应

  • sep (list) -- 指定分隔符,默认为制表符

  • indexes (list) -- 需要保留的数据列下标,从0开始。若为 None ,则所有列都保留。Default: None

  • dropna (bool) -- 是否忽略非法数据,若 False ,遇到非法数据时抛出 ValueError 。Default: True

download() → str

自动下载该数据集

返回

下载后解压目录

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.Conll2003Loader[源代码]

基类 fastNLP.io.ConllLoader

别名 fastNLP.io.Conll2003Loader fastNLP.io.loader.Conll2003Loader

用于读取conll2003任务的数据。数据的内容应该类似与以下的内容, 第一列为raw_words, 第二列为pos, 第三列为chunking,第四列为ner。

Example:

Nadim NNP B-NP B-PER
Ladki NNP I-NP I-PER

AL-AIN NNP B-NP B-LOC
United NNP B-NP B-LOC
Arab NNP I-NP I-LOC
Emirates NNPS I-NP I-LOC
1996-12-06 CD I-NP O
...

返回的DataSet的内容为

下面是Conll2003Loader加载后数据具备的结构。

raw_words

pos

chunk

ner

[Nadim, Ladki]

[NNP, NNP]

[B-NP, I-NP]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[NNP, NNP, NNP, ...]

[B-NP, B-NP, I-NP, ...]

[B-LOC, B-LOC, I-LOC, ...]

[...]

[...]

[...]

[...]

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.Conll2003NERLoader[源代码]

基类 fastNLP.io.ConllLoader

别名 fastNLP.io.Conll2003NERLoader fastNLP.io.loader.Conll2003NERLoader

用于读取conll2003任务的NER数据。每一行有4列内容,空行意味着隔开两个句子

支持读取的内容如下 Example:

Nadim NNP B-NP B-PER
Ladki NNP I-NP I-PER

AL-AIN NNP B-NP B-LOC
United NNP B-NP B-LOC
Arab NNP I-NP I-LOC
Emirates NNPS I-NP I-LOC
1996-12-06 CD I-NP O
...

返回的DataSet的内容为

下面是Conll2003Loader加载后数据具备的结构, target是BIO2编码

raw_words

target

[Nadim, Ladki]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[B-LOC, B-LOC, I-LOC, ...]

[...]

[...]

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.OntoNotesNERLoader[源代码]

基类 fastNLP.io.ConllLoader

别名 fastNLP.io.OntoNotesNERLoader fastNLP.io.loader.OntoNotesNERLoader

用以读取OntoNotes的NER数据,同时也是Conll2012的NER任务数据。将OntoNote数据处理为conll格式的过程可以参考 https://github.com/yhcc/OntoNotes-5.0-NER。OntoNoteNERLoader将取第4列和第11列的内容。

读取的数据格式为:

Example:

bc/msnbc/00/msnbc_0000   0   0          Hi   UH   (TOP(FRAG(INTJ*)  -   -   -    Dan_Abrams  *   -
bc/msnbc/00/msnbc_0000   0   1    everyone   NN              (NP*)  -   -   -    Dan_Abrams  *   -
...

返回的DataSet的内容为

raw_words

target

['Hi', 'everyone', '.']

['O', 'O', 'O']

['first', 'up', 'on', 'the', 'docket']

['O', 'O', 'O', 'O', 'O']

[...]

[...]

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.CTBLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.CTBLoader fastNLP.io.loader.CTBLoader

支持加载的数据应该具备以下格式, 其中第二列为词语,第四列为pos tag,第七列为依赖树的head,第八列为依赖树的label

Example:

1       印度    _       NR      NR      _       3       nn      _       _
2       海军    _       NN      NN      _       3       nn      _       _
3       参谋长  _       NN      NN      _       5       nsubjpass       _       _
4             _       SB      SB      _       5       pass    _       _
5       解职    _       VV      VV      _       0       root    _       _

1       新华社  _       NR      NR      _       7       dep     _       _
2       新德里  _       NR      NR      _       7       dep     _       _
3       12  _       NT      NT      _       7       dep     _       _
...

读取之后DataSet具备的格式为

raw_words

pos

dep_head

dep_label

[印度, 海军, ...]

[NR, NN, SB, ...]

[3, 3, ...]

[nn, nn, ...]

[新华社, 新德里, ...]

[NR, NR, NT, ...]

[7, 7, 7, ...]

[dep, dep, dep, ...]

[...]

[...]

[...]

[...]

download()[源代码]

由于版权限制,不能提供自动下载功能。可参考

https://catalog.ldc.upenn.edu/LDC2013T21

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.MsraNERLoader[源代码]

基类 fastNLP.io.CNNERLoader

别名 fastNLP.io.MsraNERLoader fastNLP.io.loader.MsraNERLoader

读取MSRA-NER数据,数据中的格式应该类似与下列的内容

Example:

把       O
欧       B-LOC

美       B-LOC
、       O

港       B-LOC
台       B-LOC

流       O
行       O

的       O

食       O

...

读取后的DataSet包含以下的field

raw_chars

target

['把', '欧']

['O', 'B-LOC']

['美', '、']

['B-LOC', 'O']

[...]

[...]

download(dev_ratio: float = 0.1, re_download: bool = False) → str[源代码]

自动下载MSAR-NER的数据,如果你使用该数据,请引用 Gina-Anne Levow, 2006, The Third International Chinese Language Processing Bakeoff: Word Segmentation and Named Entity Recognition.

根据dev_ratio的值随机将train中的数据取出一部分作为dev数据。下载完成后在output_dir中有train.conll, test.conll, dev.conll三个文件。

参数
  • dev_ratio (float) -- 如果路径中没有dev集,从train划分多少作为dev的数据. 如果为0,则不划分dev。

  • re_download (bool) -- 是否重新下载数据,以重新切分数据。

返回

str, 数据集的目录地址

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.WeiboNERLoader[源代码]

基类 fastNLP.io.CNNERLoader

别名 fastNLP.io.WeiboNERLoader fastNLP.io.loader.WeiboNERLoader

读取WeiboNER数据,数据中的格式应该类似与下列的内容

Example:

       B-PER.NOM
       I-PER.NOM
       I-PER.NOM

       O

...

读取后的DataSet包含以下的field

.. csv-table::

    :header: "raw_chars", "target"

    "['老', '百', '姓']", "['B-PER.NOM', 'I-PER.NOM', 'I-PER.NOM']"
    "['心']", "['O']"
    "[...]", "[...]"
download() → str[源代码]

自动下载Weibo-NER的数据,如果你使用了该数据,请引用 Nanyun Peng and Mark Dredze, 2015, Named Entity Recognition for Chinese Social Media with Jointly Trained Embeddings.

返回

str

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.PeopleDailyNERLoader[源代码]

基类 fastNLP.io.CNNERLoader

别名 fastNLP.io.PeopleDailyNERLoader fastNLP.io.loader.PeopleDailyNERLoader

支持加载的数据格式如下

Example:

 B-ORG
 I-ORG
 I-ORG
 I-ORG

 O
 B-ORG
...

读取后的DataSet包含以下的field

target列是基于BIO的编码方式

raw_chars

target

['中', '共', '中', '央']

['B-ORG', 'I-ORG', 'I-ORG', 'I-ORG']

[...]

[...]

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.CSVLoader(headers=None, sep=',', dropna=False)[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.CSVLoader fastNLP.io.loader.CSVLoader

读取CSV格式的数据集, 返回 DataSet

__init__(headers=None, sep=',', dropna=False)[源代码]
参数
  • headers (List[str]) -- CSV文件的文件头.定义每一列的属性名称,即返回的DataSet中`field`的名称 若为 None ,则将读入文件的第一行视作 headers . Default: None

  • sep (str) -- CSV文件中列与列之间的分隔符. Default: ","

  • dropna (bool) -- 是否忽略非法数据,若 True 则忽略,若 False ,在遇到非法数据时,抛出 ValueError . Default: False

download() → str

自动下载该数据集

返回

下载后解压目录

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.JsonLoader(fields=None, dropna=False)[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.JsonLoader fastNLP.io.loader.JsonLoader

别名:fastNLP.io.JsonLoader fastNLP.io.loader.JsonLoader

读取json格式数据.数据必须按行存储,每行是一个包含各类属性的json对象

param dict fields

需要读入的json属性名称, 和读入后在DataSet中存储的field_name fieldskey 必须是json对象的属性名. fieldsvalue 为读入后在DataSet存储的 field_name , value 也可为 None , 这时读入后的 field_name 与json对象对应属性同名 fields 可为 None , 这时,json对象所有属性都保存在DataSet中. Default: None

param bool dropna

是否忽略非法数据,若 True 则忽略,若 False ,在遇到非法数据时,抛出 ValueError . Default: False

download() → str

自动下载该数据集

返回

下载后解压目录

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.CWSLoader(dataset_name: str = None)[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.CWSLoader fastNLP.io.loader.CWSLoader

CWSLoader支持的数据格式为,一行一句话,不同词之间用空格隔开, 例如:

Example:

上海 浦东 开发 与 法制 建设 同步
新华社 上海 二月 十日 电 ( 记者 谢金虎 、 张持坚 )
...

该Loader读取后的DataSet具有如下的结构

raw_words

上海 浦东 开发 与 法制 建设 同步

新华社 上海 二月 十日 电 ( 记者 谢金虎 、 张持坚 )

...

__init__(dataset_name: str = None)[源代码]
参数

dataset_name (str) -- data的名称,支持pku, msra, cityu(繁体), as(繁体), None

download(dev_ratio=0.1, re_download=False) → str[源代码]

如果你使用了该数据集,请引用以下的文章:Thomas Emerson, The Second International Chinese Word Segmentation Bakeoff, 2005. 更多信息可以在http://sighan.cs.uchicago.edu/bakeoff2005/查看

参数
  • dev_ratio (float) -- 如果路径中没有dev集,从train划分多少作为dev的数据. 如果为0,则不划分dev。

  • re_download (bool) -- 是否重新下载数据,以重新切分数据。

返回

str

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.MNLILoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.MNLILoader fastNLP.io.loader.MNLILoader

读取的数据格式为:

Example:

index   promptID        pairID  genre   sentence1_binary_parse  sentence2_binary_parse  sentence1_parse sentence2_parse sentence1       sentence2       label1  gold_label
0       31193   31193n  government      ( ( Conceptually ( cream skimming ) ) ...
1       101457  101457e telephone       ( you ( ( know ( during ( ( ( the season ) and ) ( i guess ) ) )...
...

读取MNLI任务的数据,读取之后的DataSet中包含以下的内容,words0是sentence1, words1是sentence2, target是gold_label, 测试集中没 有target列。

raw_words1

raw_words2

target

Conceptually cream ...

Product and geography...

neutral

you know during the ...

You lose the things to the...

entailment

...

...

...

load(paths: str = None)[源代码]
参数

paths (str) -- 传入数据所在目录,会在该目录下寻找dev_matched.tsv, dev_mismatched.tsv, test_matched.tsv, test_mismatched.tsv, train.tsv文件夹

返回

DataBundle

download()[源代码]

如果你使用了这个数据,请引用

https://www.nyu.edu/projects/bowman/multinli/paper.pdf :return:

class fastNLP.io.QuoraLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.QuoraLoader fastNLP.io.loader.QuoraLoader

Quora matching任务的数据集Loader

支持读取的文件中的内容,应该有以下的形式, 以制表符分隔,且前三列的内容必须是:第一列是label,第二列和第三列是句子

Example:

1       How do I get funding for my web based startup idea ?    How do I get seed funding pre product ? 327970
0       Is honey a viable alternative to sugar for diabetics ?  How would you compare the United States ' euthanasia laws to Denmark ?  90348
...

加载的DataSet将具备以下的field

raw_words1

raw_words2

target

How do I get funding for my web based...

How do I get seed funding...

1

Is honey a viable alternative ...

How would you compare the United...

0

...

...

...

download()[源代码]

由于版权限制,不能提供自动下载功能。可参考

https://www.kaggle.com/c/quora-question-pairs/data

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.SNLILoader[源代码]

基类 fastNLP.io.JsonLoader

别名 fastNLP.io.SNLILoader fastNLP.io.loader.SNLILoader

文件每一行是一个sample,每一行都为一个json对象,其数据格式为:

Example:

{"annotator_labels": ["neutral", "entailment", "neutral", "neutral", "neutral"], "captionID": "4705552913.jpg#2",
 "gold_label": "neutral", "pairID": "4705552913.jpg#2r1n",
 "sentence1": "Two women are embracing while holding to go packages.",
 "sentence1_binary_parse": "( ( Two women ) ( ( are ( embracing ( while ( holding ( to ( go packages ) ) ) ) ) ) . ) )",
 "sentence1_parse": "(ROOT (S (NP (CD Two) (NNS women)) (VP (VBP are) (VP (VBG embracing) (SBAR (IN while) (S (NP (VBG holding)) (VP (TO to) (VP (VB go) (NP (NNS packages)))))))) (. .)))",
 "sentence2": "The sisters are hugging goodbye while holding to go packages after just eating lunch.",
 "sentence2_binary_parse": "( ( The sisters ) ( ( are ( ( hugging goodbye ) ( while ( holding ( to ( ( go packages ) ( after ( just ( eating lunch ) ) ) ) ) ) ) ) ) . ) )",
 "sentence2_parse": "(ROOT (S (NP (DT The) (NNS sisters)) (VP (VBP are) (VP (VBG hugging) (NP (UH goodbye)) (PP (IN while) (S (VP (VBG holding) (S (VP (TO to) (VP (VB go) (NP (NNS packages)) (PP (IN after) (S (ADVP (RB just)) (VP (VBG eating) (NP (NN lunch))))))))))))) (. .)))"
 }

读取之后的DataSet中的field情况为

下面是使用SNLILoader加载的DataSet所具备的field

target

raw_words1

raw_words2

neutral

Two women are embracing while holding..

The sisters are hugging goodbye...

entailment

Two women are embracing while holding...

Two woman are holding packages.

...

...

...

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle[源代码]

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

读取的field根据Loader初始化时传入的field决定。

参数

paths (str) -- 传入一个目录, 将在该目录下寻找snli_1.0_train.jsonl, snli_1.0_dev.jsonl 和snli_1.0_test.jsonl三个文件。

返回

返回的 DataBundle

download()[源代码]

如果您的文章使用了这份数据,请引用

http://nlp.stanford.edu/pubs/snli_paper.pdf

返回

str

class fastNLP.io.QNLILoader[源代码]

基类 fastNLP.io.JsonLoader

别名 fastNLP.io.QNLILoader fastNLP.io.loader.QNLILoader

第一行为标题(具体内容会被忽略),之后每一行是一个sample,由index、问题、句子和标签构成(以制表符分割),数据结构如下:

Example:

index   question        sentence        label
0       What came into force after the new constitution was herald?     As of that day, the new constitution heralding the Second Republic came into force.     entailment

QNLI数据集的Loader, 加载的DataSet将具备以下的field, raw_words1是question, raw_words2是sentence, target是label

raw_words1

raw_words2

target

What came into force after the new...

As of that day...

entailment

...

.

test数据集没有target列

download()[源代码]

如果您的实验使用到了该数据,请引用

https://arxiv.org/pdf/1809.05053.pdf

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.RTELoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.RTELoader fastNLP.io.loader.RTELoader

第一行为标题(具体内容会被忽略),之后每一行是一个sample,由index、句子1、句子2和标签构成(以制表符分割),数据结构如下:

Example:

index   sentence1       sentence2       label
0       Dana Reeve, the widow of the actor Christopher Reeve, has died of lung cancer at age 44, according to the Christopher Reeve Foundation. Christopher Reeve had an accident.      not_entailment

RTE数据的loader 加载的DataSet将具备以下的field, raw_words1是sentence0,raw_words2是sentence1, target是label

raw_words1

raw_words2

target

Dana Reeve, the widow of the actor...

Christopher Reeve had an...

not_entailment

...

...

test数据集没有target列

download()[源代码]

如果您的实验使用到了该数据,请引用GLUE Benchmark

https://openreview.net/pdf?id=rJ4km2R5t7

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.CNXNLILoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.CNXNLILoader fastNLP.io.loader.CNXNLILoader

数据集简介:中文句对NLI(本为multi-lingual的数据集,但是这里只取了中文的数据集)。原句子已被MOSES tokenizer处理,这里我们将其还原并重新按字tokenize 原始数据数据为:

Example:

premise hypo    label
我们 家里  一个    找到  可以   时间 我们 家里  一个   从来 没有 时间 使用  .  entailment

dev和test中的数据为csv或json格式,包括十多个field,这里只取与以上三个field中的数据 读取后的Dataset将具有以下数据结构:

raw_chars1

raw_chars2

target

我们 家里 有 一个 但 我 没 找到 我 可以 用 的 时间

我们 家里 有 一个 但 我 从来 没有 时间 使用 它 .

0

...

...

...

download() → str[源代码]

自动下载数据,该数据取自 https://arxiv.org/abs/1809.05053https://arxiv.org/pdf/1905.05526.pdf https://arxiv.org/pdf/1901.10125.pdf https://arxiv.org/pdf/1809.05053.pdf 有使用 :return:

class fastNLP.io.BQCorpusLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.BQCorpusLoader fastNLP.io.loader.BQCorpusLoader

别名: 数据集简介:句子对二分类任务(判断是否具有相同的语义) 原始数据结构为:

Example:

sentence1,sentence2,label
综合评分不足什么原因,综合评估的依据,0
什么时候我能使用微粒贷,你就赶快给我开通就行了,0

读取后的Dataset将具有以下数据结构:

raw_chars1

raw_chars2

target

综合评分不足什么原因

综合评估的依据

0

什么时候我能使用微粒贷

你就赶快给我开通就行了

0

...

...

...

download()[源代码]

由于版权限制,不能提供自动下载功能。可参考

https://github.com/ymcui/Chinese-BERT-wwm

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.LCQMCLoader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.LCQMCLoader fastNLP.io.loader.LCQMCLoader

数据集简介:句对匹配(question matching)

原始数据为:

Example:

喜欢打篮球的男生喜欢什么样的女生        爱打篮球的男生喜欢什么样的女生 1
你帮我设计小说的封面吧     谁能帮我给小说设计个封面?   0

读取后的Dataset将具有以下的数据结构

raw_chars1

raw_chars2

target

喜欢打篮球的男生喜欢什么样的女生

爱打篮球的男生喜欢什么样的女生

1

你帮我设计小说的封面吧

妇可以戴耳机听音乐吗?

0

...

...

...

download()[源代码]

由于版权限制,不能提供自动下载功能。可参考

https://github.com/ymcui/Chinese-BERT-wwm

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.CMRC2018Loader[源代码]

基类 fastNLP.io.Loader

别名 fastNLP.io.CMRC2018Loader fastNLP.io.loader.qa.CMRC2018Loader

请直接使用从fastNLP下载的数据进行处理。该数据集未提供测试集,测试需要通过上传到对应的系统进行评测

读取之后训练集DataSet将具备以下的内容,每个问题的答案只有一个

:header:"title", "context", "question", "answers", "answer_starts", "id"

范廷颂

范廷颂枢机(,),圣名保禄·若瑟()...

范廷颂是什么时候被任为主教的?

["1963年"]

["30"]

TRAIN_186_QUERY_0

范廷颂

范廷颂枢机(,),圣名保禄·若瑟()...

1990年,范廷颂担任什么职务?

["1990年被擢升为天..."]

["41"]

TRAIN_186_QUERY_1

...

...

...

...

.

...

其中title是文本的标题,多条记录可能是相同的title;id是该问题的id,具备唯一性

验证集DataSet将具备以下的内容,每个问题的答案可能有三个(有时候只是3个重复的答案)

title

context

question

answers

answer_starts

id

战国无双3

《战国无双3》()是由光荣和ω-force开发...

《战国无双3》是由哪两个公司合作开发的?

['光荣和ω-force', '光荣和ω-force', '光荣和ω-force']

[30, 30, 30]

DEV_0_QUERY_0

战国无双3

《战国无双3》()是由光荣和ω-force开发...

男女主角亦有专属声优这一模式是由谁改编的?

['村雨城', '村雨城', '任天堂游戏谜之村雨城']

[226, 226, 219]

DEV_0_QUERY_1

...

...

...

...

.

...

其中answer_starts是从0开始的index。例如"我来自a复旦大学?",其中"复"的开始index为4。另外"Russell评价说"中的说的index为9, 因为 英文和数字都直接按照character计量的。

download() → str[源代码]

如果您使用了本数据,请引用A Span-Extraction Dataset for Chinese Machine Reading Comprehension. Yiming Cui, Ting Liu, etc.

返回

load(paths: Union[str, Dict[str, str]] = None)fastNLP.io.data_bundle.DataBundle

从指定一个或多个路径中的文件中读取数据,返回 DataBundle

参数

Dict[str, str]] paths (Union[str,) --

支持以下的几种输入方式:

0.如果为None,则先查看本地是否有缓存,如果没有则自动下载并缓存。

1.传入一个目录, 该目录下名称包含train的被认为是train,包含test的被认为是test,包含dev的被认为是dev,如果检测到多个文件名包含'train'、 'dev'、 'test'则会报错:

data_bundle = xxxLoader().load('/path/to/dir')  # 返回的DataBundle中datasets根据目录下是否检测到train
#  dev、 test等有所变化,可以通过以下的方式取出DataSet
tr_data = data_bundle.get_dataset('train')
te_data = data_bundle.get_dataset('test')  # 如果目录下有文件包含test这个字段

2.传入一个dict,比如train,dev,test不在同一个目录下,或者名称中不包含train, dev, test:

paths = {'train':"/path/to/tr.conll", 'dev':"/to/validate.conll", "test":"/to/te.conll"}
data_bundle = xxxLoader().load(paths)  # 返回的DataBundle中的dataset中包含"train", "dev", "test"
dev_data = data_bundle.get_dataset('dev')

3.传入文件路径:

data_bundle = xxxLoader().load("/path/to/a/train.conll") # 返回DataBundle对象, datasets中仅包含'train'
tr_data = data_bundle.get_dataset('train')  # 取出DataSet

返回

返回的 DataBundle

class fastNLP.io.Pipe[源代码]

别名 fastNLP.io.Pipe fastNLP.io.pipe.Pipe

Pipe是fastNLP中用于处理DataBundle的类,但实际是处理DataBundle中的DataSet。所有Pipe都会在其process()函数的文档中指出该Pipe可处理的DataSet应该具备怎样的格式;在Pipe 文档中说明该Pipe返回后DataSet的格式以及其field的信息;以及新增的Vocabulary的信息。

一般情况下Pipe处理包含以下的几个过程,(1)将raw_words或raw_chars进行tokenize以切分成不同的词或字; (2) 再建立词或字的 Vocabulary , 并将词或字转换为index; (3)将target列建立词表并将target列转为index;

Pipe中提供了两个方法

-process()函数,输入为DataBundle -process_from_file()函数,输入为对应Loader的load函数可接受的类型。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle[源代码]

对输入的DataBundle进行处理,然后返回该DataBundle。

参数

data_bundle (DataBundle) -- 需要处理的DataBundle对象

返回

DataBundle

process_from_file(paths: str)fastNLP.io.data_bundle.DataBundle[源代码]

传入文件路径,生成处理好的DataBundle对象。paths支持的路径形式可以参考 :fastNLP.io.Loader.load()

参数

paths (str) --

返回

DataBundle

__init__()

Initialize self. See help(type(self)) for accurate signature.

class fastNLP.io.AGsNewsPipe(lower: bool = False, tokenizer: str = 'spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.AGsNewsPipe fastNLP.io.pipe.AGsNewsPipe

处理AG's News的数据, 处理之后DataSet中的内容如下

下面是使用AGsNewsPipe处理后的DataSet所具备的field

raw_words

target

words

seq_len

I got 'new' tires from them and within...

0

[7, 110, 22, 107, 22, 499, 59, 140, 3,...]

160

Don't waste your time. We had two dif...

0

[277, 17, 278, 38, 30, 112, 24, 85, 27...

40

...

.

[...]

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(lower: bool = False, tokenizer: str = 'spacy')[源代码]
参数
  • lower (bool) -- 是否对输入进行小写化。

  • tokenizer (str) -- 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。

process_from_file(paths=None)[源代码]
参数

paths (str) --

返回

DataBundle

process(data_bundle: fastNLP.io.data_bundle.DataBundle)

传入的DataSet应该具备如下的结构

raw_words

target

I got 'new' tires from them and...

1

Don't waste your time. We had two...

1

...

...

参数

data_bundle --

返回

class fastNLP.io.DBPediaPipe(lower: bool = False, tokenizer: str = 'spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.DBPediaPipe fastNLP.io.pipe.DBPediaPipe

处理DBPedia的数据, 处理之后DataSet中的内容如下

下面是使用DBPediaPipe处理后的DataSet所具备的field

raw_words

target

words

seq_len

I got 'new' tires from them and within...

0

[7, 110, 22, 107, 22, 499, 59, 140, 3,...]

160

Don't waste your time. We had two dif...

0

[277, 17, 278, 38, 30, 112, 24, 85, 27...

40

...

.

[...]

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(lower: bool = False, tokenizer: str = 'spacy')[源代码]
参数
  • lower (bool) -- 是否对输入进行小写化。

  • tokenizer (str) -- 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。

process_from_file(paths=None)[源代码]
参数

paths (str) --

返回

DataBundle

process(data_bundle: fastNLP.io.data_bundle.DataBundle)

传入的DataSet应该具备如下的结构

raw_words

target

I got 'new' tires from them and...

1

Don't waste your time. We had two...

1

...

...

参数

data_bundle --

返回

class fastNLP.io.YelpFullPipe(lower: bool = False, granularity=5, tokenizer: str = 'spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.YelpFullPipe fastNLP.io.pipe.YelpFullPipe

处理YelpFull的数据, 处理之后DataSet中的内容如下

下面是使用YelpFullPipe处理后的DataSet所具备的field

raw_words

target

words

seq_len

I got 'new' tires from them and within...

0

[7, 110, 22, 107, 22, 499, 59, 140, 3,...]

160

Don't waste your time. We had two dif...

0

[277, 17, 278, 38, 30, 112, 24, 85, 27...

40

...

.

[...]

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(lower: bool = False, granularity=5, tokenizer: str = 'spacy')[源代码]
参数
  • lower (bool) -- 是否对输入进行小写化。

  • granularity (int) -- 支持2, 3, 5。若为2, 则认为是2分类问题,将1、2归为1类,4、5归为一类,丢掉2;若为3, 则有3分类问题,将 1、2归为1类,3归为1类,4、5归为1类;若为5, 则有5分类问题。

  • tokenizer (str) -- 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。

process(data_bundle)[源代码]

传入的DataSet应该具备如下的结构

raw_words

target

I got 'new' tires from them and...

1

Don't waste your time. We had two...

1

...

...

参数

data_bundle --

返回

process_from_file(paths=None)[源代码]
参数

paths --

返回

DataBundle

class fastNLP.io.YelpPolarityPipe(lower: bool = False, tokenizer: str = 'spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.YelpPolarityPipe fastNLP.io.pipe.YelpPolarityPipe

处理YelpPolarity的数据, 处理之后DataSet中的内容如下

下面是使用YelpFullPipe处理后的DataSet所具备的field

raw_words

target

words

seq_len

I got 'new' tires from them and within...

0

[7, 110, 22, 107, 22, 499, 59, 140, 3,...]

160

Don't waste your time. We had two dif...

0

[277, 17, 278, 38, 30, 112, 24, 85, 27...

40

...

.

[...]

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(lower: bool = False, tokenizer: str = 'spacy')[源代码]
参数
  • lower (bool) -- 是否对输入进行小写化。

  • tokenizer (str) -- 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。

process_from_file(paths=None)[源代码]
参数

paths (str) --

返回

DataBundle

process(data_bundle: fastNLP.io.data_bundle.DataBundle)

传入的DataSet应该具备如下的结构

raw_words

target

I got 'new' tires from them and...

1

Don't waste your time. We had two...

1

...

...

参数

data_bundle --

返回

class fastNLP.io.SSTPipe(subtree=False, train_subtree=True, lower=False, granularity=5, tokenizer='spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.SSTPipe fastNLP.io.pipe.SSTPipe

经过该Pipe之后,DataSet中具备的field如下所示

下面是使用SSTPipe处理后的DataSet所具备的field

raw_words

words

target

seq_len

It 's a lovely film with lovely perfor...

1

[187, 6, 5, 132, 120, 70, 132, 188, 25...

13

No one goes unindicted here , which is...

0

[191, 126, 192, 193, 194, 4, 195, 17, ...

13

...

.

[...]

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(subtree=False, train_subtree=True, lower=False, granularity=5, tokenizer='spacy')[源代码]
参数
  • subtree (bool) -- 是否将train, test, dev数据展开为子树,扩充数据量。 Default: False

  • train_subtree (bool) -- 是否将train集通过子树扩展数据。

  • lower (bool) -- 是否对输入进行小写化。

  • granularity (int) -- 支持2, 3, 5。若为2, 则认为是2分类问题,将0、1归为1类,3、4归为一类,丢掉2;若为3, 则有3分类问题,将 0、1归为1类,2归为1类,3、4归为1类;若为5, 则有5分类问题。

  • tokenizer (str) -- 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)[源代码]

对DataBundle中的数据进行预处理。输入的DataSet应该至少拥有raw_words这一列,且内容类似与

下面是使用SSTLoader读取的DataSet所具备的field

raw_words

(2 (3 (3 Effective) (2 but)) (1 (1 too-tepid)...

(3 (3 (2 If) (3 (2 you) (3 (2 sometimes) ...

...

参数

data_bundle (DataBundle) -- 需要处理的DataBundle对象

返回

class fastNLP.io.SST2Pipe(lower=False, tokenizer='spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.SST2Pipe fastNLP.io.pipe.SST2Pipe

加载SST2的数据, 处理完成之后DataSet将拥有以下的field

raw_words

target

words

seq_len

it 's a charming and often affecting j...

1

[19, 9, 6, 111, 5, 112, 113, 114, 3]

9

unflinchingly bleak and desperate

0

[115, 116, 5, 117]

4

...

...

.

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(lower=False, tokenizer='spacy')[源代码]
参数
  • lower (bool) -- 是否对输入进行小写化。

  • tokenizer (str) -- 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。

process_from_file(paths=None)[源代码]
参数

paths (str) -- 如果为None,则自动下载并缓存到fastNLP的缓存地址。

返回

DataBundle

process(data_bundle: fastNLP.io.data_bundle.DataBundle)

传入的DataSet应该具备如下的结构

raw_words

target

I got 'new' tires from them and...

1

Don't waste your time. We had two...

1

...

...

参数

data_bundle --

返回

class fastNLP.io.IMDBPipe(lower: bool = False, tokenizer: str = 'spacy')[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.IMDBPipe fastNLP.io.pipe.IMDBPipe

经过本Pipe处理后DataSet将如下

输出DataSet的field

raw_words

target

words

seq_len

Bromwell High is a cartoon ...

0

[3, 5, 6, 9, ...]

20

Story of a man who has ...

1

[20, 43, 9, 10, ...]

31

...

.

[...]

.

其中raw_words为str类型,是原文; words是转换为index的输入; target是转换为index的目标值; words列被设置为input; target列被设置为target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   | False  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(lower: bool = False, tokenizer: str = 'spacy')[源代码]
参数
  • lower (bool) -- 是否将words列的数据小写。

  • tokenizer (str) -- 使用什么tokenizer来将句子切分为words. 支持spacy, raw两种。raw即使用空格拆分。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)[源代码]

期待的DataBunlde中输入的DataSet应该类似于如下,有两个field,raw_words和target,且均为str类型

输入DataSet的field

raw_words

target

Bromwell High is a cartoon ...

pos

Story of a man who has ...

neg

...

...

参数

data_bundle (DataBunlde) -- 传入的DataBundle中的DataSet必须包含raw_words和target两个field,且raw_words列应该为str, target列应该为str。

返回

DataBundle

process_from_file(paths=None)[源代码]
参数

paths -- 支持路径类型参见 fastNLP.io.loader.Loader 的load函数。

返回

DataBundle

class fastNLP.io.ChnSentiCorpPipe(bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.ChnSentiCorpPipe fastNLP.io.pipe.ChnSentiCorpPipe

处理之后的DataSet有以下的结构

raw_chars

target

chars

seq_len

這間酒店環境和服務態度亦算不錯,但房間空間太小~~

1

[2, 3, 4, 5, ...]

31

<荐书> 推荐所有喜欢<红楼>...

1

[10, 21, ....]

25

...

其中chars, seq_len是input,target是target dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(bigrams=False, trigrams=False)[源代码]
参数
  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)[源代码]

可以处理的DataSet应该具备以下的field

raw_chars

target

這間酒店環境和服務態度亦算不錯,但房間空間太小~~

1

<荐书> 推荐所有喜欢<红楼>...

1

...

参数

data_bundle --

返回

process_from_file(paths=None)[源代码]
参数

paths -- 支持路径类型参见 fastNLP.io.loader.Loader 的load函数。

返回

DataBundle

class fastNLP.io.THUCNewsPipe(bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.THUCNewsPipe fastNLP.io.pipe.THUCNewsPipe

处理之后的DataSet有以下的结构

raw_chars

target

chars

seq_len

马晓旭意外受伤让国奥警惕 无奈大雨格外青睐殷家军记者傅亚雨沈阳报道...

0

[409, 1197, 2146, 213, ...]

746

...

其中chars, seq_len是input,target是target dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
param bool bigrams

是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

param bool trigrams

是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)[源代码]

可处理的DataSet应具备如下的field

raw_words

target

马晓旭意外受伤让国奥警惕 无奈大雨格外青睐殷家军记者傅亚雨沈阳报道 ...

体育

...

...

参数

data_bundle --

返回

process_from_file(paths=None)[源代码]
参数

paths -- 支持路径类型参见 fastNLP.io.loader.Loader 的load函数。

返回

DataBundle

class fastNLP.io.WeiboSenti100kPipe(bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io.CLSBasePipe

别名 fastNLP.io.WeiboSenti100kPipe fastNLP.io.pipe.WeiboSenti100kPipe

处理之后的DataSet有以下的结构

raw_chars

target

chars

seq_len

六一出生的?好讽刺…… //@祭春姬:他爸爸是外星人吧 //@面孔小高:现在的孩子都怎么了 [怒][怒][怒]

0

[0, 690, 18, ...]

56

...

其中chars, seq_len是input,target是target dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |  False  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
param bool bigrams

是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

param bool trigrams

是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)[源代码]

可处理的DataSet应具备以下的field

raw_chars

target

六一出生的?好讽刺…… //@祭春姬:他爸爸是外星人吧 //@面孔小高:现在的孩子都怎么了 [怒][怒][怒]

0

...

...

参数

data_bundle --

返回

process_from_file(paths=None)[源代码]
参数

paths -- 支持路径类型参见 fastNLP.io.loader.Loader 的load函数。

返回

DataBundle

class fastNLP.io.Conll2003Pipe(chunk_encoding_type='bioes', ner_encoding_type='bioes', lower: bool = False)[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.Conll2003Pipe fastNLP.io.pipe.Conll2003Pipe

经过该Pipe后,DataSet中的内容如下

raw_words

pos

chunk

ner

words

seq_len

[Nadim, Ladki]

[0, 0]

[1, 2]

[1, 2]

[2, 3]

2

[AL-AIN, United, Arab, ...]

[1, 2...]

[3, 4...]

[3, 4...]

[4, 5, 6,...]

6

[...]

[...]

[...]

[...]

[...]

.

其中words, seq_len是input; pos, chunk, ner, seq_len是target dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+-------+-------+-------+-------+---------+
| field_names | raw_words |  pos  | chunk |  ner  | words | seq_len |
+-------------+-----------+-------+-------+-------+-------+---------+
|   is_input  |   False   | False | False | False |  True |   True  |
|  is_target  |   False   |  True |  True |  True | False |   True  |
| ignore_type |           | False | False | False | False |  False  |
|  pad_value  |           |   0   |   0   |   0   |   0   |    0    |
+-------------+-----------+-------+-------+-------+-------+---------+
__init__(chunk_encoding_type='bioes', ner_encoding_type='bioes', lower: bool = False)[源代码]
参数
  • chunk_encoding_type (str) -- 支持bioes, bio。

  • ner_encoding_type (str) -- 支持bioes, bio。

  • lower (bool) -- 是否将words列小写化后再建立词表

process(data_bundle)fastNLP.io.data_bundle.DataBundle[源代码]

输入的DataSet应该类似于如下的形式

raw_words

pos

chunk

ner

[Nadim, Ladki]

[NNP, NNP]

[B-NP, I-NP]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[NNP, NNP...]

[B-NP, B-NP, ...]

[B-LOC, B-LOC,...]

[...]

[...]

[...]

[...]

.

参数

data_bundle --

返回

传入的DataBundle

process_from_file(paths)[源代码]
参数

paths --

返回

class fastNLP.io.Conll2003Pipe(chunk_encoding_type='bioes', ner_encoding_type='bioes', lower: bool = False)[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.Conll2003Pipe fastNLP.io.pipe.Conll2003Pipe

经过该Pipe后,DataSet中的内容如下

raw_words

pos

chunk

ner

words

seq_len

[Nadim, Ladki]

[0, 0]

[1, 2]

[1, 2]

[2, 3]

2

[AL-AIN, United, Arab, ...]

[1, 2...]

[3, 4...]

[3, 4...]

[4, 5, 6,...]

6

[...]

[...]

[...]

[...]

[...]

.

其中words, seq_len是input; pos, chunk, ner, seq_len是target dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+-------+-------+-------+-------+---------+
| field_names | raw_words |  pos  | chunk |  ner  | words | seq_len |
+-------------+-----------+-------+-------+-------+-------+---------+
|   is_input  |   False   | False | False | False |  True |   True  |
|  is_target  |   False   |  True |  True |  True | False |   True  |
| ignore_type |           | False | False | False | False |  False  |
|  pad_value  |           |   0   |   0   |   0   |   0   |    0    |
+-------------+-----------+-------+-------+-------+-------+---------+
__init__(chunk_encoding_type='bioes', ner_encoding_type='bioes', lower: bool = False)[源代码]
参数
  • chunk_encoding_type (str) -- 支持bioes, bio。

  • ner_encoding_type (str) -- 支持bioes, bio。

  • lower (bool) -- 是否将words列小写化后再建立词表

process(data_bundle)fastNLP.io.data_bundle.DataBundle[源代码]

输入的DataSet应该类似于如下的形式

raw_words

pos

chunk

ner

[Nadim, Ladki]

[NNP, NNP]

[B-NP, I-NP]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[NNP, NNP...]

[B-NP, B-NP, ...]

[B-LOC, B-LOC,...]

[...]

[...]

[...]

[...]

.

参数

data_bundle --

返回

传入的DataBundle

process_from_file(paths)[源代码]
参数

paths --

返回

class fastNLP.io.Conll2003NERPipe(encoding_type: str = 'bio', lower: bool = False)[源代码]

基类 fastNLP.io._NERPipe

别名 fastNLP.io.Conll2003NERPipe fastNLP.io.pipe.Conll2003NERPipe

Conll2003的NER任务的处理Pipe, 该Pipe会(1)复制raw_words列,并命名为words; (2)在words, target列建立词表 (创建 fastNLP.Vocabulary 对象,所以在返回的DataBundle中将有两个Vocabulary); (3)将words,target列根据相应的 Vocabulary转换为index。 经过该Pipe过后,DataSet中的内容如下所示

Following is a demo layout of DataSet returned by Conll2003Loader

raw_words

target

words

seq_len

[Nadim, Ladki]

[1, 2]

[2, 3]

2

[AL-AIN, United, Arab, ...]

[3, 4,...]

[4, 5, 6,...]

6

[...]

[...]

[...]

.

raw_words列为List[str], 是未转换的原始数据; words列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有words, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
process_from_file(paths)fastNLP.io.data_bundle.DataBundle[源代码]
参数

paths -- 支持路径类型参见 fastNLP.io.loader.ConllLoader 的load函数。

返回

DataBundle

__init__(encoding_type: str = 'bio', lower: bool = False)
Param

str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。

参数

lower (bool) -- 是否将words小写化后再建立词表,绝大多数情况都不需要设置为True。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_words

target

[Nadim, Ladki]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[B-LOC, B-LOC, I-LOC, ...]

[...]

[...]

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]在传入DataBundle基础上原位修改。

Return DataBundle

class fastNLP.io.Conll2003NERPipe(encoding_type: str = 'bio', lower: bool = False)[源代码]

基类 fastNLP.io._NERPipe

别名 fastNLP.io.Conll2003NERPipe fastNLP.io.pipe.Conll2003NERPipe

Conll2003的NER任务的处理Pipe, 该Pipe会(1)复制raw_words列,并命名为words; (2)在words, target列建立词表 (创建 fastNLP.Vocabulary 对象,所以在返回的DataBundle中将有两个Vocabulary); (3)将words,target列根据相应的 Vocabulary转换为index。 经过该Pipe过后,DataSet中的内容如下所示

Following is a demo layout of DataSet returned by Conll2003Loader

raw_words

target

words

seq_len

[Nadim, Ladki]

[1, 2]

[2, 3]

2

[AL-AIN, United, Arab, ...]

[3, 4,...]

[4, 5, 6,...]

6

[...]

[...]

[...]

.

raw_words列为List[str], 是未转换的原始数据; words列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有words, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
process_from_file(paths)fastNLP.io.data_bundle.DataBundle[源代码]
参数

paths -- 支持路径类型参见 fastNLP.io.loader.ConllLoader 的load函数。

返回

DataBundle

__init__(encoding_type: str = 'bio', lower: bool = False)
Param

str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。

参数

lower (bool) -- 是否将words小写化后再建立词表,绝大多数情况都不需要设置为True。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_words

target

[Nadim, Ladki]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[B-LOC, B-LOC, I-LOC, ...]

[...]

[...]

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]在传入DataBundle基础上原位修改。

Return DataBundle

class fastNLP.io.OntoNotesNERPipe(encoding_type: str = 'bio', lower: bool = False)[源代码]

基类 fastNLP.io._NERPipe

别名 fastNLP.io.OntoNotesNERPipe fastNLP.io.pipe.OntoNotesNERPipe

处理OntoNotes的NER数据,处理之后DataSet中的field情况为

raw_words

target

words

seq_len

[Nadim, Ladki]

[1, 2]

[2, 3]

2

[AL-AIN, United, Arab, ...]

[3, 4]

[4, 5, 6,...]

6

[...]

[...]

[...]

.

raw_words列为List[str], 是未转换的原始数据; words列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有words, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', lower: bool = False)
Param

str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。

参数

lower (bool) -- 是否将words小写化后再建立词表,绝大多数情况都不需要设置为True。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_words

target

[Nadim, Ladki]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[B-LOC, B-LOC, I-LOC, ...]

[...]

[...]

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]在传入DataBundle基础上原位修改。

Return DataBundle

class fastNLP.io.OntoNotesNERPipe(encoding_type: str = 'bio', lower: bool = False)[源代码]

基类 fastNLP.io._NERPipe

别名 fastNLP.io.OntoNotesNERPipe fastNLP.io.pipe.OntoNotesNERPipe

处理OntoNotes的NER数据,处理之后DataSet中的field情况为

raw_words

target

words

seq_len

[Nadim, Ladki]

[1, 2]

[2, 3]

2

[AL-AIN, United, Arab, ...]

[3, 4]

[4, 5, 6,...]

6

[...]

[...]

[...]

.

raw_words列为List[str], 是未转换的原始数据; words列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有words, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_words | target | words | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', lower: bool = False)
Param

str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。

参数

lower (bool) -- 是否将words小写化后再建立词表,绝大多数情况都不需要设置为True。

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_words

target

[Nadim, Ladki]

[B-PER, I-PER]

[AL-AIN, United, Arab, ...]

[B-LOC, B-LOC, I-LOC, ...]

[...]

[...]

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]在传入DataBundle基础上原位修改。

Return DataBundle

class fastNLP.io.MsraNERPipe(encoding_type: str = 'bio', bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io._CNNERPipe

别名 fastNLP.io.MsraNERPipe fastNLP.io.pipe.MsraNERPipe

处理MSRA-NER的数据,处理之后的DataSet的field情况为

raw_chars

target

chars

seq_len

[相, 比, 之, 下,...]

[0, 0, 0, 0, ...]

[2, 3, 4, 5, ...]

11

[青, 岛, 海, 牛, 队, 和, ...]

[1, 2, 3, ...]

[10, 21, ....]

21

[...]

[...]

[...]

.

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', bigrams=False, trigrams=False)
参数
  • encoding_type (str) -- target列使用什么类型的encoding方式,支持bioes, bio两种。

  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_chars

target

[相, 比, 之, 下,...]

[O, O, O, O, ...]

[青, 岛, 海, 牛, 队, 和, ...]

[B-ORG, I-ORG, I-ORG, ...]

[...]

[...]

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int], 是转换为index的target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]。在传入DataBundle基础上原位修改。

返回

DataBundle

class fastNLP.io.MsraNERPipe(encoding_type: str = 'bio', bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io._CNNERPipe

别名 fastNLP.io.MsraNERPipe fastNLP.io.pipe.MsraNERPipe

处理MSRA-NER的数据,处理之后的DataSet的field情况为

raw_chars

target

chars

seq_len

[相, 比, 之, 下,...]

[0, 0, 0, 0, ...]

[2, 3, 4, 5, ...]

11

[青, 岛, 海, 牛, 队, 和, ...]

[1, 2, 3, ...]

[10, 21, ....]

21

[...]

[...]

[...]

.

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', bigrams=False, trigrams=False)
参数
  • encoding_type (str) -- target列使用什么类型的encoding方式,支持bioes, bio两种。

  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_chars

target

[相, 比, 之, 下,...]

[O, O, O, O, ...]

[青, 岛, 海, 牛, 队, 和, ...]

[B-ORG, I-ORG, I-ORG, ...]

[...]

[...]

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int], 是转换为index的target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]。在传入DataBundle基础上原位修改。

返回

DataBundle

class fastNLP.io.PeopleDailyPipe(encoding_type: str = 'bio', bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io._CNNERPipe

别名 fastNLP.io.PeopleDailyPipe fastNLP.io.pipe.PeopleDailyPipe

处理people daily的ner的数据,处理之后的DataSet的field情况为

raw_chars

target

chars

seq_len

[相, 比, 之, 下,...]

[0, 0, 0, 0, ...]

[2, 3, 4, 5, ...]

11

[青, 岛, 海, 牛, 队, 和, ...]

[1, 2, 3, ...]

[10, 21, ....]

21

[...]

[...]

[...]

.

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', bigrams=False, trigrams=False)
参数
  • encoding_type (str) -- target列使用什么类型的encoding方式,支持bioes, bio两种。

  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_chars

target

[相, 比, 之, 下,...]

[O, O, O, O, ...]

[青, 岛, 海, 牛, 队, 和, ...]

[B-ORG, I-ORG, I-ORG, ...]

[...]

[...]

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int], 是转换为index的target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]。在传入DataBundle基础上原位修改。

返回

DataBundle

class fastNLP.io.PeopleDailyPipe(encoding_type: str = 'bio', bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io._CNNERPipe

别名 fastNLP.io.PeopleDailyPipe fastNLP.io.pipe.PeopleDailyPipe

处理people daily的ner的数据,处理之后的DataSet的field情况为

raw_chars

target

chars

seq_len

[相, 比, 之, 下,...]

[0, 0, 0, 0, ...]

[2, 3, 4, 5, ...]

11

[青, 岛, 海, 牛, 队, 和, ...]

[1, 2, 3, ...]

[10, 21, ....]

21

[...]

[...]

[...]

.

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', bigrams=False, trigrams=False)
参数
  • encoding_type (str) -- target列使用什么类型的encoding方式,支持bioes, bio两种。

  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_chars

target

[相, 比, 之, 下,...]

[O, O, O, O, ...]

[青, 岛, 海, 牛, 队, 和, ...]

[B-ORG, I-ORG, I-ORG, ...]

[...]

[...]

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int], 是转换为index的target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]。在传入DataBundle基础上原位修改。

返回

DataBundle

class fastNLP.io.WeiboNERPipe(encoding_type: str = 'bio', bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io._CNNERPipe

别名 fastNLP.io.WeiboNERPipe fastNLP.io.pipe.WeiboNERPipe

处理weibo的ner的数据,处理之后的DataSet的field情况为

raw_chars

chars

target

seq_len

['老', '百', '姓']

[4, 3, 3]

[38, 39, 40]

3

['心']

[0]

[41]

1

[...]

[...]

[...]

.

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', bigrams=False, trigrams=False)
参数
  • encoding_type (str) -- target列使用什么类型的encoding方式,支持bioes, bio两种。

  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_chars

target

[相, 比, 之, 下,...]

[O, O, O, O, ...]

[青, 岛, 海, 牛, 队, 和, ...]

[B-ORG, I-ORG, I-ORG, ...]

[...]

[...]

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int], 是转换为index的target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]。在传入DataBundle基础上原位修改。

返回

DataBundle

class fastNLP.io.WeiboNERPipe(encoding_type: str = 'bio', bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io._CNNERPipe

别名 fastNLP.io.WeiboNERPipe fastNLP.io.pipe.WeiboNERPipe

处理weibo的ner的数据,处理之后的DataSet的field情况为

raw_chars

chars

target

seq_len

['老', '百', '姓']

[4, 3, 3]

[38, 39, 40]

3

['心']

[0]

[41]

1

[...]

[...]

[...]

.

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+--------+-------+---------+
| field_names | raw_chars | target | chars | seq_len |
+-------------+-----------+--------+-------+---------+
|   is_input  |   False   |  True  |  True |   True  |
|  is_target  |   False   |  True  | False |   True  |
| ignore_type |           | False  | False |  False  |
|  pad_value  |           |   0    |   0   |    0    |
+-------------+-----------+--------+-------+---------+
__init__(encoding_type: str = 'bio', bigrams=False, trigrams=False)
参数
  • encoding_type (str) -- target列使用什么类型的encoding方式,支持bioes, bio两种。

  • bigrams (bool) -- 是否增加一列bigrams. bigrams的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]。如果 设置为True,返回的DataSet将有一列名为bigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('bigrams')获取.

  • trigrams (bool) -- 是否增加一列trigrams. trigrams的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] 。如果设置为True,返回的DataSet将有一列名为trigrams, 且已经转换为了index并设置为input,对应的vocab可以通过 data_bundle.get_vocab('trigrams')获取.

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle

支持的DataSet的field为

raw_chars

target

[相, 比, 之, 下,...]

[O, O, O, O, ...]

[青, 岛, 海, 牛, 队, 和, ...]

[B-ORG, I-ORG, I-ORG, ...]

[...]

[...]

raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int], 是转换为index的target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。

参数

data_bundle (DataBundle) -- 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]。在传入DataBundle基础上原位修改。

返回

DataBundle

class fastNLP.io.CWSPipe(dataset_name=None, encoding_type='bmes', replace_num_alpha=True, bigrams=False, trigrams=False)[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.CWSPipe fastNLP.io.pipe.CWSPipe

对CWS数据进行预处理, 处理之后的数据,具备以下的结构

raw_words

chars

target

seq_len

共同 创造 美好...

[2, 3, 4...]

[0, 2, 0, 2,...]

13

2001年 新年 钟声...

[8, 9, 9, 7, ...]

[0, 1, 1, 1, 2...]

20

...

[...]

[...]

.

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+-----------+-------+--------+---------+
| field_names | raw_words | chars | target | seq_len |
+-------------+-----------+-------+--------+---------+
|   is_input  |   False   |  True |  True  |   True  |
|  is_target  |   False   | False |  True  |   True  |
| ignore_type |           | False | False  |  False  |
|  pad_value  |           |   0   |   0    |    0    |
+-------------+-----------+-------+--------+---------+
__init__(dataset_name=None, encoding_type='bmes', replace_num_alpha=True, bigrams=False, trigrams=False)[源代码]
参数
  • dataset_name (str,None) -- 支持'pku', 'msra', 'cityu', 'as', None

  • encoding_type (str) -- 可以选择'bmes', 'segapp'两种。"我 来自 复旦大学...", bmes的tag为[S, B, E, B, M, M, E...]; segapp 的tag为[seg, app, seg, app, app, app, seg, ...]

  • replace_num_alpha (bool) -- 是否将数字和字母用特殊字符替换。

  • bigrams (bool) -- 是否增加一列bigram. bigram的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...]

  • trigrams (bool) -- 是否增加一列trigram. trigram的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...]

process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle[源代码]

可以处理的DataSet需要包含raw_words列

raw_words

上海 浦东 开发 与 法制 建设 同步

新华社 上海 二月 十日 电 ( 记者 谢金虎 、 张持坚 )

...

参数

data_bundle --

返回

process_from_file(paths=None)fastNLP.io.data_bundle.DataBundle[源代码]
参数

paths (str) --

返回

class fastNLP.io.MatchingBertPipe(lower=False, tokenizer: str = 'raw')[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.MatchingBertPipe fastNLP.io.pipe.MatchingBertPipe

Matching任务的Bert pipe,输出的DataSet将包含以下的field

raw_words1

raw_words2

target

words

seq_len

The new rights are...

Everyone really likes..

1

[2, 3, 4, 5, ...]

10

This site includes a...

The Government Executive...

0

[11, 12, 13,...]

5

...

...

.

[...]

.

words列是将raw_words1(即premise), raw_words2(即hypothesis)使用"[SEP]"链接起来转换为index的。 words列被设置为input,target列被设置为target和input(设置为input以方便在forward函数中计算loss, 如果不在forward函数中计算loss也不影响,fastNLP将根据forward函数的形参名进行传参).

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+------------+------------+--------+-------+---------+
| field_names | raw_words1 | raw_words2 | target | words | seq_len |
+-------------+------------+------------+--------+-------+---------+
|   is_input  |   False    |   False    | False  |  True |   True  |
|  is_target  |   False    |   False    |  True  | False |  False  |
| ignore_type |            |            | False  | False |  False  |
|  pad_value  |            |            |   0    |   0   |    0    |
+-------------+------------+------------+--------+-------+---------+
__init__(lower=False, tokenizer: str = 'raw')[源代码]
参数
  • lower (bool) -- 是否将word小写化。

  • tokenizer (str) -- 使用什么tokenizer来将句子切分为words. 支持spacy, raw两种。raw即使用空格拆分。

process(data_bundle)[源代码]

输入的data_bundle中的dataset需要具有以下结构:

raw_words1

raw_words2

target

Dana Reeve, the widow of the actor...

Christopher Reeve had an...

not_entailment

...

...

参数

data_bundle --

返回

process_from_file(paths: str)fastNLP.io.data_bundle.DataBundle

传入文件路径,生成处理好的DataBundle对象。paths支持的路径形式可以参考 :fastNLP.io.Loader.load()

参数

paths (str) --

返回

DataBundle

class fastNLP.io.MatchingPipe(lower=False, tokenizer: str = 'raw')[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.MatchingPipe fastNLP.io.pipe.MatchingPipe

Matching任务的Pipe。输出的DataSet将包含以下的field

raw_words1

raw_words2

target

words1

words2

seq_len1

seq_len2

The new rights are...

Everyone really likes..

1

[2, 3, 4, 5, ...]

[10, 20, 6]

10

13

This site includes a...

The Government Executive...

0

[11, 12, 13,...]

[2, 7, ...]

6

7

...

...

.

[...]

[...]

.

.

words1是premise,words2是hypothesis。其中words1,words2,seq_len1,seq_len2被设置为input;target被设置为target 和input(设置为input以方便在forward函数中计算loss,如果不在forward函数中计算loss也不影响,fastNLP将根据forward函数 的形参名进行传参)。

dataset的print_field_meta()函数输出的各个field的被设置成input和target的情况为:

+-------------+------------+------------+--------+--------+--------+----------+----------+
| field_names | raw_words1 | raw_words2 | target | words1 | words2 | seq_len1 | seq_len2 |
+-------------+------------+------------+--------+--------+--------+----------+----------+
|   is_input  |   False    |   False    | False  |  True  |  True  |   True   |   True   |
|  is_target  |   False    |   False    |  True  | False  | False  |  False   |  False   |
| ignore_type |            |            | False  | False  | False  |  False   |  False   |
|  pad_value  |            |            |   0    |   0    |   0    |    0     |    0     |
+-------------+------------+------------+--------+--------+--------+----------+----------+
__init__(lower=False, tokenizer: str = 'raw')[源代码]
参数
  • lower (bool) -- 是否将所有raw_words转为小写。

  • tokenizer (str) -- 将原始数据tokenize的方式。支持spacy, raw. spacy是使用spacy切分,raw就是用空格切分。

process(data_bundle)[源代码]

接受的DataBundle中的DataSet应该具有以下的field, target列可以没有

raw_words1

raw_words2

target

The new rights are...

Everyone really likes..

entailment

This site includes a...

The Government Executive...

not_entailment

...

...

参数

data_bundle (DataBundle) -- 通过loader读取得到的data_bundle,里面包含了数据集的原始数据内容

返回

data_bundle

process_from_file(paths: str)fastNLP.io.data_bundle.DataBundle

传入文件路径,生成处理好的DataBundle对象。paths支持的路径形式可以参考 :fastNLP.io.Loader.load()

参数

paths (str) --

返回

DataBundle

class fastNLP.io.CMRC2018BertPipe(max_len=510)[源代码]

基类 fastNLP.io.Pipe

别名 fastNLP.io.CMRC2018BertPipe fastNLP.io.pipe.qa.CMRC2018BertPipe

处理之后的DataSet将新增以下的field(传入的field仍然保留)

context_len

raw_chars

target_start

target_end

chars

492

['范'

'廷'

'颂... ]

30

34

[21, 25, ...]

491

['范'

'廷'

'颂... ]

41

61

[21, 25, ...]

.

...

...

...

...

raw_words列是context与question拼起来的结果(连接的地方加入了[SEP]),words是转为index的值, target_start为答案start的index,target_end为答案end的index (闭区间);context_len指示的是words列中context的长度。

其中各列的meta信息如下:

+-------------+-------------+-----------+--------------+------------+-------+---------+
| field_names | context_len | raw_chars | target_start | target_end | chars | answers |
+-------------+-------------+-----------+--------------+------------+-------+---------|
|   is_input  |    False    |   False   |    False     |   False    |  True |  False  |
|  is_target  |     True    |    True   |     True     |    True    | False |  True   |
| ignore_type |    False    |    True   |    False     |   False    | False |  True   |
|  pad_value  |      0      |     0     |      0       |     0      |   0   |   0     |
+-------------+-------------+-----------+--------------+------------+-------+---------+
process(data_bundle: fastNLP.io.data_bundle.DataBundle)fastNLP.io.data_bundle.DataBundle[源代码]

传入的DataSet应该具备以下的field

:header:"title", "context", "question", "answers", "answer_starts", "id"

范廷颂

范廷颂枢机(,),圣名保禄·若瑟()...

范廷颂是什么时候被任为主教的?

["1963年"]

["30"]

TRAIN_186_QUERY_0

范廷颂

范廷颂枢机(,),圣名保禄·若瑟()...

1990年,范廷颂担任什么职务?

["1990年被擢升为天..."]

["41"]

TRAIN_186_QUERY_1

...

...

...

...

.

...

参数

data_bundle --

返回

class fastNLP.io.ModelLoader[源代码]

别名 fastNLP.io.ModelLoader fastNLP.io.model_io.ModelLoader

用于读取模型

static load_pytorch(empty_model, model_path)[源代码]

从 ".pkl" 文件读取 PyTorch 模型

参数
  • empty_model -- 初始化参数的 PyTorch 模型

  • model_path (str) -- 模型保存的路径

static load_pytorch_model(model_path)[源代码]

读取整个模型

参数

model_path (str) -- 模型保存的路径

class fastNLP.io.ModelSaver(save_path)[源代码]

别名 fastNLP.io.ModelSaver fastNLP.io.model_io.ModelSaver

用于保存模型

Example:

saver = ModelSaver("./save/model_ckpt_100.pkl")
saver.save_pytorch(model)
__init__(save_path)[源代码]
参数

save_path -- 模型保存的路径

save_pytorch(model, param_only=True)[源代码]

把 PyTorch 模型存入 ".pkl" 文件

参数
  • model -- PyTorch 模型

  • param_only (bool) -- 是否只保存模型的参数(否则保存整个模型)