diff --git a/fastNLP/io/data_bundle.py b/fastNLP/io/data_bundle.py index 19b48828..1f05cf68 100644 --- a/fastNLP/io/data_bundle.py +++ b/fastNLP/io/data_bundle.py @@ -6,9 +6,11 @@ __all__ = [ 'DataBundle', ] +from typing import Union + from ..core.dataset import DataSet from ..core.vocabulary import Vocabulary -from typing import Union + class DataBundle: """ @@ -22,11 +24,14 @@ class DataBundle: train_data = data_bundle.datasets['train'] dev_data = data_bundle.datasets['train'] - :param vocabs: 从名称(字符串)到 :class:`~fastNLP.Vocabulary` 类型的dict - :param datasets: 从名称(字符串)到 :class:`~fastNLP.DataSet` 类型的dict """ def __init__(self, vocabs: dict = None, datasets: dict = None): + """ + + :param vocabs: 从名称(字符串)到 :class:`~fastNLP.Vocabulary` 类型的dict + :param datasets: 从名称(字符串)到 :class:`~fastNLP.DataSet` 类型的dict + """ self.vocabs = vocabs or {} self.datasets = datasets or {} diff --git a/fastNLP/io/loader/conll.py b/fastNLP/io/loader/conll.py index f30b031f..0526628d 100644 --- a/fastNLP/io/loader/conll.py +++ b/fastNLP/io/loader/conll.py @@ -53,13 +53,15 @@ class ConllLoader(Loader): 数据中以"-DOCSTART-"开头的行将被忽略,因为该符号在conll 2003中被用为文档分割符。 - :param list headers: 每一列数据的名称,需为List or Tuple of str。``header`` 与 ``indexes`` 一一对应 - :param list indexes: 需要保留的数据列下标,从0开始。若为 ``None`` ,则所有列都保留。Default: ``None`` - :param bool dropna: 是否忽略非法数据,若 ``False`` ,遇到非法数据时抛出 ``ValueError`` 。Default: ``True`` - """ def __init__(self, headers, indexes=None, dropna=True): + """ + + :param list headers: 每一列数据的名称,需为List or Tuple of str。``header`` 与 ``indexes`` 一一对应 + :param list indexes: 需要保留的数据列下标,从0开始。若为 ``None`` ,则所有列都保留。Default: ``None`` + :param bool dropna: 是否忽略非法数据,若 ``False`` ,遇到非法数据时抛出 ``ValueError`` 。Default: ``True`` + """ super(ConllLoader, self).__init__() if not isinstance(headers, (list, tuple)): raise TypeError( diff --git a/fastNLP/io/loader/csv.py b/fastNLP/io/loader/csv.py index aaf38c00..6f35efbe 100644 --- a/fastNLP/io/loader/csv.py +++ b/fastNLP/io/loader/csv.py @@ -14,14 +14,17 @@ class CSVLoader(Loader): """ 读取CSV格式的数据集, 返回 ``DataSet`` 。 - :param List[str] headers: CSV文件的文件头.定义每一列的属性名称,即返回的DataSet中`field`的名称 - 若为 ``None`` ,则将读入文件的第一行视作 ``headers`` . Default: ``None`` - :param str sep: CSV文件中列与列之间的分隔符. Default: "," - :param bool dropna: 是否忽略非法数据,若 ``True`` 则忽略,若 ``False`` ,在遇到非法数据时,抛出 ``ValueError`` . - Default: ``False`` """ def __init__(self, headers=None, sep=",", dropna=False): + """ + + :param List[str] headers: CSV文件的文件头.定义每一列的属性名称,即返回的DataSet中`field`的名称 + 若为 ``None`` ,则将读入文件的第一行视作 ``headers`` . Default: ``None`` + :param str sep: CSV文件中列与列之间的分隔符. Default: "," + :param bool dropna: 是否忽略非法数据,若 ``True`` 则忽略,若 ``False`` ,在遇到非法数据时,抛出 ``ValueError`` . + Default: ``False`` + """ super().__init__() self.headers = headers self.sep = sep diff --git a/fastNLP/io/loader/cws.py b/fastNLP/io/loader/cws.py index 2fbb1091..887bb545 100644 --- a/fastNLP/io/loader/cws.py +++ b/fastNLP/io/loader/cws.py @@ -33,10 +33,13 @@ class CWSLoader(Loader): "上海 浦东 开发 与 法制 建设 同步" "新华社 上海 二月 十日 电 ( 记者 谢金虎 、 张持坚 )" "..." - - :param: str dataset_name: data的名称,支持pku, msra, cityu(繁体), as(繁体), None + """ def __init__(self, dataset_name:str=None): + """ + + :param str dataset_name: data的名称,支持pku, msra, cityu(繁体), as(繁体), None + """ super().__init__() datanames = {'pku': 'cws-pku', 'msra':'cws-msra', 'as':'cws-as', 'cityu':'cws-cityu'} if dataset_name in datanames: diff --git a/fastNLP/io/loader/json.py b/fastNLP/io/loader/json.py index 671769fe..6e988baa 100644 --- a/fastNLP/io/loader/json.py +++ b/fastNLP/io/loader/json.py @@ -14,15 +14,18 @@ class JsonLoader(Loader): """ 读取json格式数据.数据必须按行存储,每行是一个包含各类属性的json对象 - :param dict fields: 需要读入的json属性名称, 和读入后在DataSet中存储的field_name - ``fields`` 的 `key` 必须是json对象的属性名. ``fields`` 的 `value` 为读入后在DataSet存储的 `field_name` , - `value` 也可为 ``None`` , 这时读入后的 `field_name` 与json对象对应属性同名 - ``fields`` 可为 ``None`` , 这时,json对象所有属性都保存在DataSet中. Default: ``None`` - :param bool dropna: 是否忽略非法数据,若 ``True`` 则忽略,若 ``False`` ,在遇到非法数据时,抛出 ``ValueError`` . - Default: ``False`` """ def __init__(self, fields=None, dropna=False): + """ + + :param dict fields: 需要读入的json属性名称, 和读入后在DataSet中存储的field_name + ``fields`` 的 `key` 必须是json对象的属性名. ``fields`` 的 `value` 为读入后在DataSet存储的 `field_name` , + `value` 也可为 ``None`` , 这时读入后的 `field_name` 与json对象对应属性同名 + ``fields`` 可为 ``None`` , 这时,json对象所有属性都保存在DataSet中. Default: ``None`` + :param bool dropna: 是否忽略非法数据,若 ``True`` 则忽略,若 ``False`` ,在遇到非法数据时,抛出 ``ValueError`` . + Default: ``False`` + """ super(JsonLoader, self).__init__() self.dropna = dropna self.fields = None diff --git a/fastNLP/io/loader/matching.py b/fastNLP/io/loader/matching.py index a21d0845..b713fc9a 100644 --- a/fastNLP/io/loader/matching.py +++ b/fastNLP/io/loader/matching.py @@ -128,7 +128,7 @@ class SNLILoader(JsonLoader): def load(self, paths: Union[str, Dict[str, str]] = None) -> DataBundle: """ - 从指定一个或多个路径中的文件中读取数据,返回:class:`~fastNLP.io.DataBundle` 。 + 从指定一个或多个路径中的文件中读取数据,返回 :class:`~fastNLP.io.DataBundle` 。 读取的field根据ConllLoader初始化时传入的headers决定。 diff --git a/fastNLP/io/pipe/classification.py b/fastNLP/io/pipe/classification.py index 3834a570..450c2058 100644 --- a/fastNLP/io/pipe/classification.py +++ b/fastNLP/io/pipe/classification.py @@ -16,12 +16,12 @@ from nltk import Tree from .pipe import Pipe from .utils import get_tokenizer, _indexize, _add_words_field, _drop_empty_instance, _add_chars_field from ..data_bundle import DataBundle +from ..loader.classification import ChnSentiCorpLoader from ..loader.classification import IMDBLoader, YelpFullLoader, SSTLoader, SST2Loader, YelpPolarityLoader from ...core.const import Const from ...core.dataset import DataSet from ...core.instance import Instance from ...core.vocabulary import Vocabulary -from ..loader.classification import ChnSentiCorpLoader nonalpnum = re.compile('[^0-9a-zA-Z?!\']+') @@ -33,6 +33,7 @@ class _CLSPipe(Pipe): """ def __init__(self, tokenizer: str = 'spacy', lang='en'): + self.tokenizer = get_tokenizer(tokenizer, lang=lang) def _tokenize(self, data_bundle, field_name=Const.INPUT, new_field_name=None): @@ -98,13 +99,16 @@ class YelpFullPipe(_CLSPipe): "Offers that ...", "[20, 40, ...]", 1, 21 "...", "[...]", ., . - :param bool lower: 是否对输入进行小写化。 - :param int granularity: 支持2, 3, 5。若为2, 则认为是2分类问题,将1、2归为1类,4、5归为一类,丢掉2;若为3, 则有3分类问题,将 - 1、2归为1类,3归为1类,4、5归为1类;若为5, 则有5分类问题。 - :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 """ def __init__(self, lower: bool = False, granularity=5, tokenizer: str = 'spacy'): + """ + + :param bool lower: 是否对输入进行小写化。 + :param int granularity: 支持2, 3, 5。若为2, 则认为是2分类问题,将1、2归为1类,4、5归为一类,丢掉2;若为3, 则有3分类问题,将 + 1、2归为1类,3归为1类,4、5归为1类;若为5, 则有5分类问题。 + :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 + """ super().__init__(tokenizer=tokenizer, lang='en') self.lower = lower assert granularity in (2, 3, 5), "granularity can only be 2,3,5." @@ -191,11 +195,14 @@ class YelpPolarityPipe(_CLSPipe): "Offers that ...", "[20, 40, ...]", 1, 21 "...", "[...]", ., . - :param bool lower: 是否对输入进行小写化。 - :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 """ def __init__(self, lower: bool = False, tokenizer: str = 'spacy'): + """ + + :param bool lower: 是否对输入进行小写化。 + :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 + """ super().__init__(tokenizer=tokenizer, lang='en') self.lower = lower @@ -237,15 +244,18 @@ class SSTPipe(_CLSPipe): "Offers that ...", "[20, 40, ...]", 1, 18 "...", "[...]", ., . - :param bool subtree: 是否将train, test, dev数据展开为子树,扩充数据量。 Default: ``False`` - :param bool train_subtree: 是否将train集通过子树扩展数据。 - :param bool lower: 是否对输入进行小写化。 - :param int granularity: 支持2, 3, 5。若为2, 则认为是2分类问题,将0、1归为1类,3、4归为一类,丢掉2;若为3, 则有3分类问题,将 - 0、1归为1类,2归为1类,3、4归为1类;若为5, 则有5分类问题。 - :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 """ def __init__(self, subtree=False, train_subtree=True, lower=False, granularity=5, tokenizer='spacy'): + """ + + :param bool subtree: 是否将train, test, dev数据展开为子树,扩充数据量。 Default: ``False`` + :param bool train_subtree: 是否将train集通过子树扩展数据。 + :param bool lower: 是否对输入进行小写化。 + :param int granularity: 支持2, 3, 5。若为2, 则认为是2分类问题,将0、1归为1类,3、4归为一类,丢掉2;若为3, 则有3分类问题,将 + 0、1归为1类,2归为1类,3、4归为1类;若为5, 则有5分类问题。 + :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 + """ super().__init__(tokenizer=tokenizer, lang='en') self.subtree = subtree self.train_tree = train_subtree @@ -327,11 +337,14 @@ class SST2Pipe(_CLSPipe): "unflinchingly bleak and...", "[10, 11, 7,...]", 1, 21 "...", "...", ., . - :param bool lower: 是否对输入进行小写化。 - :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 """ def __init__(self, lower=False, tokenizer='spacy'): + """ + + :param bool lower: 是否对输入进行小写化。 + :param str tokenizer: 使用哪种tokenize方式将数据切成单词。支持'spacy'和'raw'。raw使用空格作为切分。 + """ super().__init__(tokenizer=tokenizer, lang='en') self.lower = lower @@ -402,11 +415,14 @@ class IMDBPipe(_CLSPipe): 其中raw_words为str类型,是原文; words是转换为index的输入; target是转换为index的目标值; words列被设置为input; target列被设置为target。 - :param bool lower: 是否将words列的数据小写。 - :param str tokenizer: 使用什么tokenizer来将句子切分为words. 支持spacy, raw两种。raw即使用空格拆分。 """ def __init__(self, lower: bool = False, tokenizer: str = 'spacy'): + """ + + :param bool lower: 是否将words列的数据小写。 + :param str tokenizer: 使用什么tokenizer来将句子切分为words. 支持spacy, raw两种。raw即使用空格拆分。 + """ super().__init__(tokenizer=tokenizer, lang='en') self.lower = lower @@ -471,14 +487,17 @@ class ChnSentiCorpPipe(Pipe): 其中chars, seq_len是input,target是target - :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')获取. """ def __init__(self, bigrams=False, trigrams=False): + """ + + :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')获取. + """ super().__init__() self.bigrams = bigrams diff --git a/fastNLP/io/pipe/conll.py b/fastNLP/io/pipe/conll.py index 12a94d20..24ba2ba0 100644 --- a/fastNLP/io/pipe/conll.py +++ b/fastNLP/io/pipe/conll.py @@ -54,7 +54,7 @@ class _NERPipe(Pipe): "[...]", "[...]" :param ~fastNLP.DataBundle data_bundle: 传入的DataBundle中的DataSet必须包含raw_words和ner两个field,且两个field的内容均为List[str]在传入DataBundle基础上原位修改。 - :return DataBundle: + :return DataBundle: """ # 转换tag for name, dataset in data_bundle.datasets.items(): @@ -94,8 +94,6 @@ class Conll2003NERPipe(_NERPipe): raw_words列为List[str], 是未转换的原始数据; words列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有words, target, seq_len; 设置为target有target。 - :param: str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。 - :param bool lower: 是否将words小写化后再建立词表,绝大多数情况都不需要设置为True。 """ def process_from_file(self, paths) -> DataBundle: @@ -112,18 +110,21 @@ class Conll2003NERPipe(_NERPipe): class Conll2003Pipe(Pipe): - def __init__(self, chunk_encoding_type='bioes', ner_encoding_type='bioes', lower: bool = False): - """ - 经过该Pipe后,DataSet中的内容如下 + r""" + 经过该Pipe后,DataSet中的内容如下 - .. csv-table:: - :header: "raw_words", "words", "pos", "chunk", "ner", "seq_len" + .. csv-table:: + :header: "raw_words" , "words", "pos", "chunk", "ner", "seq_len" - "[Nadim, Ladki]", "[2, 3]", "[0, 0]", "[1, 2]", "[1, 2]", 2 - "[AL-AIN, United, Arab, ...]", "[4, 5, 6,...]", "[1, 2...]", "[3, 4...]", "[3, 4...]", 6 - "[...]", "[...]", "[...]", "[...]", "[...]". + "[Nadim, Ladki]", "[2, 3]", "[0, 0]", "[1, 2]", "[1, 2]", 2 + "[AL-AIN, United, Arab, ...]", "[4, 5, 6,...]", "[1, 2...]", "[3, 4...]", "[3, 4...]", 6 + "[...]", "[...]", "[...]", "[...]", "[...]", . - 其中words, seq_len是input; pos, chunk, ner, seq_len是target + 其中words, seq_len是input; pos, chunk, ner, seq_len是target + + """ + def __init__(self, chunk_encoding_type='bioes', ner_encoding_type='bioes', lower: bool = False): + """ :param str chunk_encoding_type: 支持bioes, bio。 :param str ner_encoding_type: 支持bioes, bio。 @@ -148,7 +149,7 @@ class Conll2003Pipe(Pipe): "[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,...]" - "[...]", "[...]", "[...]", "[...]". + "[...]", "[...]", "[...]", "[...]", . :param data_bundle: :return: 传入的DataBundle @@ -204,8 +205,6 @@ class OntoNotesNERPipe(_NERPipe): raw_words列为List[str], 是未转换的原始数据; words列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有words, target, seq_len; 设置为target有target。 - :param: str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。 - :param bool lower: 是否将words小写化后再建立词表,绝大多数情况都不需要设置为True。 """ def process_from_file(self, paths): @@ -222,16 +221,19 @@ class _CNNERPipe(Pipe): raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target, seq_len。 - :param: str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。 - :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')获取. """ def __init__(self, encoding_type: str = 'bio', bigrams=False, trigrams=False): + """ + + :param str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。 + :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')获取. + """ if encoding_type == 'bio': self.convert_tag = iob2 else: @@ -346,7 +348,6 @@ class WeiboNERPipe(_CNNERPipe): raw_chars列为List[str], 是未转换的原始数据; chars列为List[int],是转换为index的输入数据; target列是List[int],是转换为index的 target。返回的DataSet中被设置为input有chars, target, seq_len; 设置为target有target。 - :param: str encoding_type: target列使用什么类型的encoding方式,支持bioes, bio两种。 """ def process_from_file(self, paths=None) -> DataBundle: diff --git a/fastNLP/io/pipe/coreference.py b/fastNLP/io/pipe/coreference.py index b6d88998..3c171507 100644 --- a/fastNLP/io/pipe/coreference.py +++ b/fastNLP/io/pipe/coreference.py @@ -5,13 +5,15 @@ __all__ = [ ] +import collections + +import numpy as np + +from fastNLP.core.vocabulary import Vocabulary from .pipe import Pipe from ..data_bundle import DataBundle from ..loader.coreference import CRLoader from ...core.const import Const -from fastNLP.core.vocabulary import Vocabulary -import numpy as np -import collections class CoreferencePipe(Pipe): @@ -25,8 +27,8 @@ class CoreferencePipe(Pipe): def process(self, data_bundle: DataBundle): """ - 对load进来的数据进一步处理 - 原始数据包含:raw_key,raw_speaker,raw_words,raw_clusters + 对load进来的数据进一步处理原始数据包含:raw_key,raw_speaker,raw_words,raw_clusters + .. csv-table:: :header: "raw_key", "raw_speaker","raw_words","raw_clusters" @@ -35,6 +37,7 @@ class CoreferencePipe(Pipe): "[...]", "[...]","[...]","[...]" 处理完成后数据包含文章类别、speaker信息、句子信息、句子对应的index、char、句子长度、target: + .. csv-table:: :header: "words1", "words2","words3","words4","chars","seq_len","target" diff --git a/fastNLP/io/pipe/cws.py b/fastNLP/io/pipe/cws.py index 748cf10a..1fc64785 100644 --- a/fastNLP/io/pipe/cws.py +++ b/fastNLP/io/pipe/cws.py @@ -146,15 +146,18 @@ class CWSPipe(Pipe): 其中bigrams仅当bigrams列为True的时候为真 - :param str,None dataset_name: 支持'pku', 'msra', 'cityu', 'as', None - :param str encoding_type: 可以选择'bmes', 'segapp'两种。"我 来自 复旦大学...", bmes的tag为[S, B, E, B, M, M, E...]; segapp - 的tag为[seg, app, seg, app, app, app, seg, ...] - :param bool replace_num_alpha: 是否将数字和字母用特殊字符替换。 - :param bool bigrams: 是否增加一列bigram. bigram的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...] - :param bool trigrams: 是否增加一列trigram. trigram的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] """ def __init__(self, dataset_name=None, encoding_type='bmes', replace_num_alpha=True, bigrams=False, trigrams=False): + """ + + :param str,None dataset_name: 支持'pku', 'msra', 'cityu', 'as', None + :param str encoding_type: 可以选择'bmes', 'segapp'两种。"我 来自 复旦大学...", bmes的tag为[S, B, E, B, M, M, E...]; segapp + 的tag为[seg, app, seg, app, app, app, seg, ...] + :param bool replace_num_alpha: 是否将数字和字母用特殊字符替换。 + :param bool bigrams: 是否增加一列bigram. bigram的构成是['复', '旦', '大', '学', ...]->["复旦", "旦大", ...] + :param bool trigrams: 是否增加一列trigram. trigram的构成是 ['复', '旦', '大', '学', ...]->["复旦大", "旦大学", ...] + """ if encoding_type == 'bmes': self.word_lens_to_tags = _word_lens_to_bmes else: @@ -253,7 +256,7 @@ class CWSPipe(Pipe): def process_from_file(self, paths=None) -> DataBundle: """ - + :param str paths: :return: """ diff --git a/fastNLP/io/pipe/matching.py b/fastNLP/io/pipe/matching.py index 747e7b44..3db79aef 100644 --- a/fastNLP/io/pipe/matching.py +++ b/fastNLP/io/pipe/matching.py @@ -37,11 +37,14 @@ class MatchingBertPipe(Pipe): words列被设置为input,target列被设置为target和input(设置为input以方便在forward函数中计算loss, 如果不在forward函数中计算loss也不影响,fastNLP将根据forward函数的形参名进行传参). - :param bool lower: 是否将word小写化。 - :param str tokenizer: 使用什么tokenizer来将句子切分为words. 支持spacy, raw两种。raw即使用空格拆分。 """ def __init__(self, lower=False, tokenizer: str = 'raw'): + """ + + :param bool lower: 是否将word小写化。 + :param str tokenizer: 使用什么tokenizer来将句子切分为words. 支持spacy, raw两种。raw即使用空格拆分。 + """ super().__init__() self.lower = bool(lower) @@ -163,12 +166,14 @@ class MatchingPipe(Pipe): words1是premise,words2是hypothesis。其中words1,words2,seq_len1,seq_len2被设置为input;target被设置为target 和input(设置为input以方便在forward函数中计算loss,如果不在forward函数中计算loss也不影响,fastNLP将根据forward函数 的形参名进行传参)。 - - :param bool lower: 是否将所有raw_words转为小写。 - :param str tokenizer: 将原始数据tokenize的方式。支持spacy, raw. spacy是使用spacy切分,raw就是用空格切分。 """ def __init__(self, lower=False, tokenizer: str = 'raw'): + """ + + :param bool lower: 是否将所有raw_words转为小写。 + :param str tokenizer: 将原始数据tokenize的方式。支持spacy, raw. spacy是使用spacy切分,raw就是用空格切分。 + """ super().__init__() self.lower = bool(lower) diff --git a/fastNLP/io/pipe/pipe.py b/fastNLP/io/pipe/pipe.py index 07735d91..20bafe01 100644 --- a/fastNLP/io/pipe/pipe.py +++ b/fastNLP/io/pipe/pipe.py @@ -13,6 +13,7 @@ class Pipe: doc """ + def process(self, data_bundle: DataBundle) -> DataBundle: """ 对输入的DataBundle进行处理,然后返回该DataBundle。