fastNLP.api

fastNLP.api.api

class fastNLP.api.api.POS(model_path=None, device='cpu')[source]

FastNLP API for Part-Of-Speech tagging.

Parameters:
  • model_path (str) – the path to the model.
  • device (str) – device name such as “cpu” or “cuda:0”. Use the same notation as PyTorch.
predict(content)[source]
Parameters:content – list of list of str. Each string is a token(word).
Return answer:list of list of str. Each string is a tag.

fastNLP.api.converter

fastNLP.api.model_zoo

fastNLP.api.pipeline

class fastNLP.api.pipeline.Pipeline(processors=None)[source]

Pipeline takes a DataSet object as input, runs multiple processors sequentially, and outputs a DataSet object.

fastNLP.api.processor

class fastNLP.api.processor.FullSpaceToHalfSpaceProcessor(field_name, change_alpha=True, change_digit=True, change_punctuation=True, change_space=True)[source]

全角转半角,以字符为处理单元

class fastNLP.api.processor.Index2WordProcessor(vocab, field_name, new_added_field_name)[source]

将DataSet中某个为index的field根据vocab转换为str

class fastNLP.api.processor.IndexerProcessor(vocab, field_name, new_added_field_name, delete_old_field=False, is_input=True)[source]
给定一个vocabulary , 将指定field转换为index形式。指定field应该是一维的list,比如
[‘我’, ‘是’, xxx]
class fastNLP.api.processor.Num2TagProcessor(tag, field_name, new_added_field_name=None)[source]

将一句话中的数字转换为某个tag。

class fastNLP.api.processor.PreAppendProcessor(data, field_name, new_added_field_name=None)[source]
向某个field的起始增加data(应该为str类型)。该field需要为list类型。即新增的field为
[data] + instance[field_name]
class fastNLP.api.processor.SeqLenProcessor(field_name, new_added_field_name='seq_lens', is_input=True)[source]

根据某个field新增一个sequence length的field。取该field的第一维

class fastNLP.api.processor.SliceProcessor(start, end, step, field_name, new_added_field_name=None)[source]

从某个field中只取部分内容。等价于instance[field_name][start:end:step]

class fastNLP.api.processor.VocabProcessor(field_name, min_freq=1, max_size=None)[source]

传入若干个DataSet以建立vocabulary。