From 2c9484c274c73bcfb6f0324e18957f54750b7294 Mon Sep 17 00:00:00 2001 From: yunfan Date: Wed, 24 Apr 2019 11:04:32 +0800 Subject: [PATCH 1/3] - update doc --- fastNLP/io/__init__.py | 36 +++++++++++++++++++++ fastNLP/io/config_io.py | 5 +++ fastNLP/io/dataset_loader.py | 18 ++++++++++- fastNLP/io/embed_loader.py | 5 +++ fastNLP/io/model_io.py | 5 +++ fastNLP/models/biaffine_parser.py | 2 ++ fastNLP/models/star_transformer.py | 2 ++ fastNLP/modules/encoder/lstm.py | 7 ++-- fastNLP/modules/encoder/star_transformer.py | 2 ++ fastNLP/modules/encoder/variational_rnn.py | 25 +++++++++----- requirements.txt | 6 ++-- 11 files changed, 99 insertions(+), 14 deletions(-) diff --git a/fastNLP/io/__init__.py b/fastNLP/io/__init__.py index a3b18aa5..e8ccca30 100644 --- a/fastNLP/io/__init__.py +++ b/fastNLP/io/__init__.py @@ -1 +1,37 @@ +""" +用于IO的模块, 具体包括: + +1. 用于读入 embedding 的 :ref:`EmbedLoader ` 类, + +2. 用于读入数据的 :ref:`DataSetLoader ` 类 + +3. 用于读写config文件的类, 参考 :ref:`Config-io ` + +4. 用于保存和载入模型的类, 参考 :ref:`Model-io ` + +这些类的使用方法可以在对应module的文档下查看. +""" from .embed_loader import EmbedLoader +from .dataset_loader import * +from .config_io import * +from .model_io import * + +__all__ = [ + 'EmbedLoader', + + 'DataSetLoader', + 'CSVLoader', + 'JsonLoader', + 'ConllLoader', + 'SNLILoader', + 'SSTLoader', + 'PeopleDailyCorpusLoader', + 'Conll2003Loader', + + 'ConfigLoader', + 'ConfigSection', + 'ConfigSaver', + + 'ModelLoader', + 'ModelSaver', +] \ No newline at end of file diff --git a/fastNLP/io/config_io.py b/fastNLP/io/config_io.py index c0ffe53e..f303f0e9 100644 --- a/fastNLP/io/config_io.py +++ b/fastNLP/io/config_io.py @@ -1,3 +1,8 @@ +""" +.. _config-io: + +用于读入和处理和保存 config 文件 +""" import configparser import json import os diff --git a/fastNLP/io/dataset_loader.py b/fastNLP/io/dataset_loader.py index 039c4242..bb5e2f64 100644 --- a/fastNLP/io/dataset_loader.py +++ b/fastNLP/io/dataset_loader.py @@ -1,3 +1,18 @@ +""" +.. _dataset-loader: + +DataSetLoader 的 API, 用于读取不同格式的数据, 并返回 `DataSet` , +得到的 `DataSet` 对象可以直接传入 `Trainer`, `Tester`, 用于模型的训练和测试 + +Example:: + + loader = SNLILoader() + train_ds = loader.load('path/to/train') + dev_ds = loader.load('path/to/dev') + test_ds = loader.load('path/to/test') + + # ... do stuff +""" import os import json from nltk.tree import Tree @@ -55,8 +70,9 @@ def _uncompress(src, dst): class DataSetLoader: - """所有`DataSetLoader`的接口 + """ + 所有`DataSetLoader`的接口 """ def load(self, path): diff --git a/fastNLP/io/embed_loader.py b/fastNLP/io/embed_loader.py index e1f20b94..7f055b3f 100644 --- a/fastNLP/io/embed_loader.py +++ b/fastNLP/io/embed_loader.py @@ -1,3 +1,8 @@ +""" +.. _embed-loader: + +用于读取预训练的embedding, 读取结果可直接载入为模型参数 +""" import os import numpy as np diff --git a/fastNLP/io/model_io.py b/fastNLP/io/model_io.py index 53bdc7ce..d28034c8 100644 --- a/fastNLP/io/model_io.py +++ b/fastNLP/io/model_io.py @@ -1,3 +1,8 @@ +""" +.. _model-io: + +用于载入和保存模型 +""" import torch from fastNLP.io.base_loader import BaseLoader diff --git a/fastNLP/models/biaffine_parser.py b/fastNLP/models/biaffine_parser.py index 9a070c92..59d95558 100644 --- a/fastNLP/models/biaffine_parser.py +++ b/fastNLP/models/biaffine_parser.py @@ -1,3 +1,5 @@ +"""Biaffine Dependency Parser 的 Pytorch 实现. +""" from collections import defaultdict import numpy as np diff --git a/fastNLP/models/star_transformer.py b/fastNLP/models/star_transformer.py index 4f4ed551..f68aca42 100644 --- a/fastNLP/models/star_transformer.py +++ b/fastNLP/models/star_transformer.py @@ -1,3 +1,5 @@ +"""Star-Transformer 的 一个 Pytorch 实现. +""" from fastNLP.modules.encoder.star_transformer import StarTransformer from fastNLP.core.utils import seq_lens_to_masks diff --git a/fastNLP/modules/encoder/lstm.py b/fastNLP/modules/encoder/lstm.py index 9ab8e273..cff39c84 100644 --- a/fastNLP/modules/encoder/lstm.py +++ b/fastNLP/modules/encoder/lstm.py @@ -1,3 +1,6 @@ +"""轻量封装的 Pytorch LSTM 模块. +可在 forward 时传入序列的长度, 自动对padding做合适的处理. +""" import torch import torch.nn as nn import torch.nn.utils.rnn as rnn @@ -35,8 +38,8 @@ class LSTM(nn.Module): :param h0: [batch, hidden_size] 初始隐状态, 若为 ``None`` , 设为全1向量. Default: ``None`` :param c0: [batch, hidden_size] 初始Cell状态, 若为 ``None`` , 设为全1向量. Default: ``None`` :return (output, ht) 或 output: 若 ``get_hidden=True`` [batch, seq_len, hidden_size*num_direction] 输出序列 - :和 [batch, hidden_size*num_direction] 最后时刻隐状态. - :若 ``get_hidden=False`` 仅返回输出序列. + 和 [batch, hidden_size*num_direction] 最后时刻隐状态. + 若 ``get_hidden=False`` 仅返回输出序列. """ if h0 is not None and c0 is not None: hx = (h0, c0) diff --git a/fastNLP/modules/encoder/star_transformer.py b/fastNLP/modules/encoder/star_transformer.py index 034cfa96..42662804 100644 --- a/fastNLP/modules/encoder/star_transformer.py +++ b/fastNLP/modules/encoder/star_transformer.py @@ -1,3 +1,5 @@ +"""Star-Transformer 的encoder部分的 Pytorch 实现 +""" import torch from torch import nn from torch.nn import functional as F diff --git a/fastNLP/modules/encoder/variational_rnn.py b/fastNLP/modules/encoder/variational_rnn.py index d63aa6e7..89ab44d9 100644 --- a/fastNLP/modules/encoder/variational_rnn.py +++ b/fastNLP/modules/encoder/variational_rnn.py @@ -1,3 +1,5 @@ +"""Variational RNN 的 Pytorch 实现 +""" import torch import torch.nn as nn from torch.nn.utils.rnn import PackedSequence, pack_padded_sequence, pad_packed_sequence @@ -28,11 +30,11 @@ class VarRnnCellWrapper(nn.Module): """ :param PackedSequence input_x: [seq_len, batch_size, input_size] :param hidden: for LSTM, tuple of (h_0, c_0), [batch_size, hidden_size] - :for other RNN, h_0, [batch_size, hidden_size] + for other RNN, h_0, [batch_size, hidden_size] :param mask_x: [batch_size, input_size] dropout mask for input :param mask_h: [batch_size, hidden_size] dropout mask for hidden :return PackedSequence output: [seq_len, bacth_size, hidden_size] - :hidden: for LSTM, tuple of (h_n, c_n), [batch_size, hidden_size] + hidden: for LSTM, tuple of (h_n, c_n), [batch_size, hidden_size] for other RNN, h_n, [batch_size, hidden_size] """ def get_hi(hi, h0, size): @@ -95,7 +97,7 @@ class VarRNNBase(nn.Module): :param num_layers: rnn的层数. Default: 1 :param bias: 如果为 ``False``, 模型将不会使用bias. Default: ``True`` :param batch_first: 若为 ``True``, 输入和输出 ``Tensor`` 形状为 - :(batch, seq, feature). Default: ``False`` + (batch, seq, feature). Default: ``False`` :param input_dropout: 对输入的dropout概率. Default: 0 :param hidden_dropout: 对每个隐状态的dropout概率. Default: 0 :param bidirectional: 若为 ``True``, 使用双向的RNN. Default: ``False`` @@ -138,7 +140,7 @@ class VarRNNBase(nn.Module): :param x: [batch, seq_len, input_size] 输入序列 :param hx: [batch, hidden_size] 初始隐状态, 若为 ``None`` , 设为全1向量. Default: ``None`` :return (output, ht): [batch, seq_len, hidden_size*num_direction] 输出序列 - :和 [batch, hidden_size*num_direction] 最后时刻隐状态 + 和 [batch, hidden_size*num_direction] 最后时刻隐状态 """ is_lstm = self.is_lstm is_packed = isinstance(x, PackedSequence) @@ -193,7 +195,6 @@ class VarRNNBase(nn.Module): return output, hidden - class VarLSTM(VarRNNBase): """Variational Dropout LSTM. @@ -202,7 +203,7 @@ class VarLSTM(VarRNNBase): :param num_layers: rnn的层数. Default: 1 :param bias: 如果为 ``False``, 模型将不会使用bias. Default: ``True`` :param batch_first: 若为 ``True``, 输入和输出 ``Tensor`` 形状为 - :(batch, seq, feature). Default: ``False`` + (batch, seq, feature). Default: ``False`` :param input_dropout: 对输入的dropout概率. Default: 0 :param hidden_dropout: 对每个隐状态的dropout概率. Default: 0 :param bidirectional: 若为 ``True``, 使用双向的LSTM. Default: ``False`` @@ -211,6 +212,9 @@ class VarLSTM(VarRNNBase): def __init__(self, *args, **kwargs): super(VarLSTM, self).__init__(mode="LSTM", Cell=nn.LSTMCell, *args, **kwargs) + def forward(self, x, hx=None): + return super(VarLSTM, self).forward(x, hx) + class VarRNN(VarRNNBase): """Variational Dropout RNN. @@ -220,7 +224,7 @@ class VarRNN(VarRNNBase): :param num_layers: rnn的层数. Default: 1 :param bias: 如果为 ``False``, 模型将不会使用bias. Default: ``True`` :param batch_first: 若为 ``True``, 输入和输出 ``Tensor`` 形状为 - :(batch, seq, feature). Default: ``False`` + (batch, seq, feature). Default: ``False`` :param input_dropout: 对输入的dropout概率. Default: 0 :param hidden_dropout: 对每个隐状态的dropout概率. Default: 0 :param bidirectional: 若为 ``True``, 使用双向的RNN. Default: ``False`` @@ -229,6 +233,8 @@ class VarRNN(VarRNNBase): def __init__(self, *args, **kwargs): super(VarRNN, self).__init__(mode="RNN", Cell=nn.RNNCell, *args, **kwargs) + def forward(self, x, hx=None): + return super(VarRNN, self).forward(x, hx) class VarGRU(VarRNNBase): """Variational Dropout GRU. @@ -238,7 +244,7 @@ class VarGRU(VarRNNBase): :param num_layers: rnn的层数. Default: 1 :param bias: 如果为 ``False``, 模型将不会使用bias. Default: ``True`` :param batch_first: 若为 ``True``, 输入和输出 ``Tensor`` 形状为 - :(batch, seq, feature). Default: ``False`` + (batch, seq, feature). Default: ``False`` :param input_dropout: 对输入的dropout概率. Default: 0 :param hidden_dropout: 对每个隐状态的dropout概率. Default: 0 :param bidirectional: 若为 ``True``, 使用双向的GRU. Default: ``False`` @@ -247,6 +253,9 @@ class VarGRU(VarRNNBase): def __init__(self, *args, **kwargs): super(VarGRU, self).__init__(mode="GRU", Cell=nn.GRUCell, *args, **kwargs) + def forward(self, x, hx=None): + return super(VarGRU, self).forward(x, hx) + # if __name__ == '__main__': # x = torch.Tensor([[1,2,3], [4,5,0], [6,0,0]])[:,:,None] * 0.1 # mask = (x != 0).float().view(3, -1) diff --git a/requirements.txt b/requirements.txt index 931ca285..d763ea1b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -numpy>=1.14.2 +numpy torch>=0.4.0 tensorboardX -tqdm>=4.28.1 -nltk>=3.4.1 \ No newline at end of file +tqdm +nltk \ No newline at end of file From 46d72c7439524a07672168dce735407501651811 Mon Sep 17 00:00:00 2001 From: yunfan Date: Thu, 25 Apr 2019 22:14:26 +0800 Subject: [PATCH 2/3] - update doc - add get_embeddings --- fastNLP/core/vocabulary.py | 33 ++++++++++++++++++------------ fastNLP/models/biaffine_parser.py | 13 ++++++------ fastNLP/models/star_transformer.py | 11 ++++++---- fastNLP/modules/utils.py | 23 +++++++++++++++++++++ 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/fastNLP/core/vocabulary.py b/fastNLP/core/vocabulary.py index 6a1830ad..6779a282 100644 --- a/fastNLP/core/vocabulary.py +++ b/fastNLP/core/vocabulary.py @@ -231,22 +231,29 @@ class Vocabulary(object): vocab.from_dataset(train_data1, train_data2, field_name='words') :param DataSet datasets: 需要转index的 DataSet, 支持一个或多个. - :param str field_name: 构建词典所使用的 field. - 若有多个 DataSet, 每个DataSet都必须有此 field. - 目前仅支持 ``str`` , ``list(str)`` , ``list(list(str))`` + :param field_name: 可为 ``str`` 或 ``list(str)`` . + 构建词典所使用的 field(s), 支持一个或多个field + 若有多个 DataSet, 每个DataSet都必须有这些field. + 目前仅支持的field结构: ``str`` , ``list(str)`` , ``list(list(str))`` :return self: """ + if isinstance(field_name, str): + field_name = [field_name] + elif not isinstance(field_name, list): + raise TypeError('invalid argument field_name: {}'.format(field_name)) + def construct_vocab(ins): - field = ins[field_name] - if isinstance(field, str): - self.add_word(field) - elif isinstance(field, list): - if not isinstance(field[0], list): - self.add_word_lst(field) - else: - if isinstance(field[0][0], list): - raise RuntimeError("Only support field with 2 dimensions.") - [self.add_word_lst(w) for w in field] + for fn in field_name: + field = ins[fn] + if isinstance(field, str): + self.add_word(field) + elif isinstance(field, list): + if not isinstance(field[0], list): + self.add_word_lst(field) + else: + if isinstance(field[0][0], list): + raise RuntimeError("Only support field with 2 dimensions.") + [self.add_word_lst(w) for w in field] for idx, dataset in enumerate(datasets): if isinstance(dataset, DataSet): try: diff --git a/fastNLP/models/biaffine_parser.py b/fastNLP/models/biaffine_parser.py index 59d95558..f2329dca 100644 --- a/fastNLP/models/biaffine_parser.py +++ b/fastNLP/models/biaffine_parser.py @@ -16,7 +16,7 @@ from fastNLP.modules.encoder.transformer import TransformerEncoder from fastNLP.modules.encoder.variational_rnn import VarLSTM from fastNLP.modules.utils import initial_parameter from fastNLP.modules.utils import seq_mask - +from fastNLP.modules.utils import get_embeddings def _mst(scores): """ @@ -230,8 +230,9 @@ class BiaffineParser(GraphParser): 论文参考 ` Deep Biaffine Attention for Neural Dependency Parsing (Dozat and Manning, 2016) `_ . - :param word_vocab_size: 单词词典大小 - :param word_emb_dim: 单词词嵌入向量的维度 + :param init_embed: 单词词典, 可以是 tuple, 包括(num_embedings, embedding_dim), 即 + embedding的大小和每个词的维度. 也可以传入 nn.Embedding 对象, + 此时就以传入的对象作为embedding :param pos_vocab_size: part-of-speech 词典大小 :param pos_emb_dim: part-of-speech 向量维度 :param num_label: 边的类别个数 @@ -245,8 +246,7 @@ class BiaffineParser(GraphParser): 若 ``False`` , 使用更加精确但相对缓慢的MST算法. Default: ``False`` """ def __init__(self, - word_vocab_size, - word_emb_dim, + init_embed, pos_vocab_size, pos_emb_dim, num_label, @@ -260,7 +260,8 @@ class BiaffineParser(GraphParser): super(BiaffineParser, self).__init__() rnn_out_size = 2 * rnn_hidden_size word_hid_dim = pos_hid_dim = rnn_hidden_size - self.word_embedding = nn.Embedding(num_embeddings=word_vocab_size, embedding_dim=word_emb_dim) + self.word_embedding = get_embeddings(init_embed) + word_emb_dim = self.word_embedding.embedding_dim self.pos_embedding = nn.Embedding(num_embeddings=pos_vocab_size, embedding_dim=pos_emb_dim) self.word_fc = nn.Linear(word_emb_dim, word_hid_dim) self.pos_fc = nn.Linear(pos_emb_dim, pos_hid_dim) diff --git a/fastNLP/models/star_transformer.py b/fastNLP/models/star_transformer.py index f68aca42..e4fbeb28 100644 --- a/fastNLP/models/star_transformer.py +++ b/fastNLP/models/star_transformer.py @@ -2,6 +2,7 @@ """ from fastNLP.modules.encoder.star_transformer import StarTransformer from fastNLP.core.utils import seq_lens_to_masks +from ..modules.utils import get_embeddings import torch from torch import nn @@ -12,8 +13,9 @@ class StarTransEnc(nn.Module): """ 带word embedding的Star-Transformer Encoder - :param vocab_size: 词嵌入的词典大小 - :param emb_dim: 每个词嵌入的特征维度 + :param init_embed: 单词词典, 可以是 tuple, 包括(num_embedings, embedding_dim), 即 + embedding的大小和每个词的维度. 也可以传入 nn.Embedding 对象, + 此时就以传入的对象作为embedding :param num_cls: 输出类别个数 :param hidden_size: 模型中特征维度. :param num_layers: 模型层数. @@ -24,7 +26,7 @@ class StarTransEnc(nn.Module): :param emb_dropout: 词嵌入的dropout概率. :param dropout: 模型除词嵌入外的dropout概率. """ - def __init__(self, vocab_size, emb_dim, + def __init__(self, init_embed, hidden_size, num_layers, num_head, @@ -33,9 +35,10 @@ class StarTransEnc(nn.Module): emb_dropout, dropout): super(StarTransEnc, self).__init__() + self.embedding = get_embeddings(init_embed) + emb_dim = self.embedding.embedding_dim self.emb_fc = nn.Linear(emb_dim, hidden_size) self.emb_drop = nn.Dropout(emb_dropout) - self.embedding = nn.Embedding(vocab_size, emb_dim) self.encoder = StarTransformer(hidden_size=hidden_size, num_layers=num_layers, num_head=num_head, diff --git a/fastNLP/modules/utils.py b/fastNLP/modules/utils.py index 4ae15b18..56dbb894 100644 --- a/fastNLP/modules/utils.py +++ b/fastNLP/modules/utils.py @@ -1,3 +1,4 @@ +import numpy as np import torch import torch.nn as nn import torch.nn.init as init @@ -88,3 +89,25 @@ def seq_mask(seq_len, max_len): seq_len = seq_len.view(-1, 1).long() # [batch_size, 1] seq_range = torch.arange(start=0, end=max_len, dtype=torch.long, device=seq_len.device).view(1, -1) # [1, max_len] return torch.gt(seq_len, seq_range) # [batch_size, max_len] + + +def get_embeddings(init_embed): + """得到词嵌入 + + :param init_embed: 单词词典, 可以是 tuple, 包括(num_embedings, embedding_dim), 即 + embedding的大小和每个词的维度. 也可以传入 nn.Embedding 对象, + 此时就以传入的对象作为embedding + :return embeddings: + """ + if isinstance(init_embed, tuple): + res = nn.Embedding(num_embeddings=init_embed[0], embedding_dim=init_embed[1]) + elif isinstance(init_embed, nn.Embedding): + res = init_embed + elif isinstance(init_embed, torch.Tensor): + res = nn.Embedding.from_pretrained(init_embed, freeze=False) + elif isinstance(init_embed, np.ndarray): + init_embed = torch.tensor(init_embed, dtype=torch.float32) + res = nn.Embedding.from_pretrained(init_embed, freeze=False) + else: + raise TypeError('invalid init_embed type: {}'.format((type(init_embed)))) + return res From a7a9fc34b4b9c47c4869a738ad8404766be7499f Mon Sep 17 00:00:00 2001 From: ChenXin Date: Fri, 26 Apr 2019 13:11:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/Makefile | 2 +- docs/source/conf.py | 32 ++++++++----- docs/source/fastNLP.api.rst | 12 +++-- docs/source/fastNLP.automl.rst | 44 ++++++++++++++++++ docs/source/fastNLP.component.rst | 20 +++++++++ docs/source/fastNLP.core.rst | 12 +++-- docs/source/fastNLP.io.rst | 36 +++++++-------- docs/source/fastNLP.models.rst | 52 +++++++++++----------- docs/source/fastNLP.modules.aggregator.rst | 42 ++++------------- docs/source/fastNLP.modules.decoder.rst | 12 +++-- docs/source/fastNLP.modules.encoder.rst | 42 +++++++++-------- docs/source/fastNLP.modules.rst | 16 +++---- docs/source/fastNLP.rst | 13 +++--- 13 files changed, 189 insertions(+), 146 deletions(-) create mode 100644 docs/source/fastNLP.automl.rst create mode 100644 docs/source/fastNLP.component.rst diff --git a/docs/Makefile b/docs/Makefile index 6a2ed12a..3050e655 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -14,7 +14,7 @@ help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) apidoc: - @$(SPHINXAPIDOC) -fM -o source ../fastNLP + $(SPHINXAPIDOC) -fM -o source ../$(SPHINXPROJ) server: cd build/html && python -m http.server diff --git a/docs/source/conf.py b/docs/source/conf.py index 96f7f437..5fd9e56d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -14,6 +14,7 @@ # import os import sys + sys.path.insert(0, os.path.abspath('../../')) # -- Project information ----------------------------------------------------- @@ -27,7 +28,6 @@ version = '0.4' # The full version, including alpha/beta/rc tags release = '0.4' - # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. @@ -42,9 +42,15 @@ extensions = [ 'sphinx.ext.viewcode', 'sphinx.ext.autosummary', 'sphinx.ext.mathjax', - + 'sphinx.ext.todo' ] +autodoc_default_options = { + 'member-order': 'bysource', + 'special-members': '__init__', + 'undoc-members': True, +} + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -72,7 +78,6 @@ exclude_patterns = ['modules.rst'] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' - # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -107,22 +112,21 @@ html_static_path = ['_static'] # Output file base name for HTML help builder. htmlhelp_basename = 'fastNLPdoc' - # -- Options for LaTeX output ------------------------------------------------ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - + # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - + # Additional stuff for the LaTeX preamble. # # 'preamble': '', - + # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -136,7 +140,6 @@ latex_documents = [ 'xpqiu', 'manual'), ] - # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples @@ -146,7 +149,6 @@ man_pages = [ [author], 1) ] - # -- Options for Texinfo output ---------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples @@ -159,4 +161,14 @@ texinfo_documents = [ ] -# -- Extension configuration ------------------------------------------------- \ No newline at end of file +# -- Extension configuration ------------------------------------------------- +def maybe_skip_member(app, what, name, obj, skip, options): + if name.startswith("_"): + return True + if obj.__doc__ is None: + return True + return False + + +def setup(app): + app.connect('autodoc-skip-member', maybe_skip_member) diff --git a/docs/source/fastNLP.api.rst b/docs/source/fastNLP.api.rst index ee2413fb..955eb8c5 100644 --- a/docs/source/fastNLP.api.rst +++ b/docs/source/fastNLP.api.rst @@ -1,6 +1,11 @@ fastNLP.api package =================== +.. automodule:: fastNLP.api + :members: + :undoc-members: + :show-inheritance: + Submodules ---------- @@ -53,10 +58,3 @@ fastNLP.api.utils module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.api - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.automl.rst b/docs/source/fastNLP.automl.rst new file mode 100644 index 00000000..3c12e271 --- /dev/null +++ b/docs/source/fastNLP.automl.rst @@ -0,0 +1,44 @@ +fastNLP.automl package +====================== + +.. automodule:: fastNLP.automl + :members: + :undoc-members: + :show-inheritance: + +Submodules +---------- + +fastNLP.automl.enas\_controller module +-------------------------------------- + +.. automodule:: fastNLP.automl.enas_controller + :members: + :undoc-members: + :show-inheritance: + +fastNLP.automl.enas\_model module +--------------------------------- + +.. automodule:: fastNLP.automl.enas_model + :members: + :undoc-members: + :show-inheritance: + +fastNLP.automl.enas\_trainer module +----------------------------------- + +.. automodule:: fastNLP.automl.enas_trainer + :members: + :undoc-members: + :show-inheritance: + +fastNLP.automl.enas\_utils module +--------------------------------- + +.. automodule:: fastNLP.automl.enas_utils + :members: + :undoc-members: + :show-inheritance: + + diff --git a/docs/source/fastNLP.component.rst b/docs/source/fastNLP.component.rst new file mode 100644 index 00000000..81fcf561 --- /dev/null +++ b/docs/source/fastNLP.component.rst @@ -0,0 +1,20 @@ +fastNLP.component package +========================= + +.. automodule:: fastNLP.component + :members: + :undoc-members: + :show-inheritance: + +Submodules +---------- + +fastNLP.component.bert\_tokenizer module +---------------------------------------- + +.. automodule:: fastNLP.component.bert_tokenizer + :members: + :undoc-members: + :show-inheritance: + + diff --git a/docs/source/fastNLP.core.rst b/docs/source/fastNLP.core.rst index 79d26c76..540bd03c 100644 --- a/docs/source/fastNLP.core.rst +++ b/docs/source/fastNLP.core.rst @@ -1,6 +1,11 @@ fastNLP.core package ==================== +.. automodule:: fastNLP.core + :members: + :undoc-members: + :show-inheritance: + Submodules ---------- @@ -117,10 +122,3 @@ fastNLP.core.vocabulary module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.core - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.io.rst b/docs/source/fastNLP.io.rst index e677b50a..1eb95c6a 100644 --- a/docs/source/fastNLP.io.rst +++ b/docs/source/fastNLP.io.rst @@ -1,51 +1,56 @@ fastNLP.io package ================== +.. automodule:: fastNLP.io + :members: + :undoc-members: + :show-inheritance: + Submodules ---------- -fastNLP.io.base_loader module ------------------------------ +fastNLP.io.base\_loader module +------------------------------ .. automodule:: fastNLP.io.base_loader :members: :undoc-members: :show-inheritance: -fastNLP.io.config_io module ---------------------------- +fastNLP.io.config\_io module +---------------------------- .. automodule:: fastNLP.io.config_io :members: :undoc-members: :show-inheritance: -fastNLP.io.dataset_loader module --------------------------------- +fastNLP.io.dataset\_loader module +--------------------------------- .. automodule:: fastNLP.io.dataset_loader :members: :undoc-members: :show-inheritance: -fastNLP.io.embed_loader module ------------------------------- +fastNLP.io.embed\_loader module +------------------------------- .. automodule:: fastNLP.io.embed_loader :members: :undoc-members: :show-inheritance: -fastNLP.io.file_reader module ------------------------------ +fastNLP.io.file\_reader module +------------------------------ .. automodule:: fastNLP.io.file_reader :members: :undoc-members: :show-inheritance: -fastNLP.io.model_io module --------------------------- +fastNLP.io.model\_io module +--------------------------- .. automodule:: fastNLP.io.model_io :members: @@ -53,10 +58,3 @@ fastNLP.io.model_io module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.io - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.models.rst b/docs/source/fastNLP.models.rst index ccf6abb2..18b8186f 100644 --- a/docs/source/fastNLP.models.rst +++ b/docs/source/fastNLP.models.rst @@ -1,11 +1,16 @@ fastNLP.models package ====================== +.. automodule:: fastNLP.models + :members: + :undoc-members: + :show-inheritance: + Submodules ---------- -fastNLP.models.base_model module --------------------------------- +fastNLP.models.base\_model module +--------------------------------- .. automodule:: fastNLP.models.base_model :members: @@ -20,64 +25,64 @@ fastNLP.models.bert module :undoc-members: :show-inheritance: -fastNLP.models.biaffine_parser module -------------------------------------- +fastNLP.models.biaffine\_parser module +-------------------------------------- .. automodule:: fastNLP.models.biaffine_parser :members: :undoc-members: :show-inheritance: -fastNLP.models.char_language_model module ------------------------------------------ +fastNLP.models.char\_language\_model module +------------------------------------------- .. automodule:: fastNLP.models.char_language_model :members: :undoc-members: :show-inheritance: -fastNLP.models.cnn_text_classification module ---------------------------------------------- +fastNLP.models.cnn\_text\_classification module +----------------------------------------------- .. automodule:: fastNLP.models.cnn_text_classification :members: :undoc-members: :show-inheritance: -fastNLP.models.enas_controller module -------------------------------------- +fastNLP.models.enas\_controller module +-------------------------------------- .. automodule:: fastNLP.models.enas_controller :members: :undoc-members: :show-inheritance: -fastNLP.models.enas_model module --------------------------------- +fastNLP.models.enas\_model module +--------------------------------- .. automodule:: fastNLP.models.enas_model :members: :undoc-members: :show-inheritance: -fastNLP.models.enas_trainer module ----------------------------------- +fastNLP.models.enas\_trainer module +----------------------------------- .. automodule:: fastNLP.models.enas_trainer :members: :undoc-members: :show-inheritance: -fastNLP.models.enas_utils module --------------------------------- +fastNLP.models.enas\_utils module +--------------------------------- .. automodule:: fastNLP.models.enas_utils :members: :undoc-members: :show-inheritance: -fastNLP.models.sequence_modeling module ---------------------------------------- +fastNLP.models.sequence\_modeling module +---------------------------------------- .. automodule:: fastNLP.models.sequence_modeling :members: @@ -92,8 +97,8 @@ fastNLP.models.snli module :undoc-members: :show-inheritance: -fastNLP.models.star_transformer module --------------------------------------- +fastNLP.models.star\_transformer module +--------------------------------------- .. automodule:: fastNLP.models.star_transformer :members: @@ -101,10 +106,3 @@ fastNLP.models.star_transformer module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.models - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.modules.aggregator.rst b/docs/source/fastNLP.modules.aggregator.rst index 478ac218..74ff5aed 100644 --- a/docs/source/fastNLP.modules.aggregator.rst +++ b/docs/source/fastNLP.modules.aggregator.rst @@ -1,54 +1,28 @@ fastNLP.modules.aggregator package ================================== -Submodules ----------- - -fastNLP.modules.aggregator.attention module -------------------------------------------- - -.. automodule:: fastNLP.modules.aggregator.attention +.. automodule:: fastNLP.modules.aggregator :members: :undoc-members: :show-inheritance: -fastNLP.modules.aggregator.avg_pool module ------------------------------------------- - -.. automodule:: fastNLP.modules.aggregator.avg_pool - :members: - :undoc-members: - :show-inheritance: +Submodules +---------- -fastNLP.modules.aggregator.kmax_pool module +fastNLP.modules.aggregator.attention module ------------------------------------------- -.. automodule:: fastNLP.modules.aggregator.kmax_pool - :members: - :undoc-members: - :show-inheritance: - -fastNLP.modules.aggregator.max_pool module ------------------------------------------- - -.. automodule:: fastNLP.modules.aggregator.max_pool +.. automodule:: fastNLP.modules.aggregator.attention :members: :undoc-members: :show-inheritance: -fastNLP.modules.aggregator.self_attention module ------------------------------------------------- +fastNLP.modules.aggregator.pooling module +----------------------------------------- -.. automodule:: fastNLP.modules.aggregator.self_attention +.. automodule:: fastNLP.modules.aggregator.pooling :members: :undoc-members: :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.modules.aggregator - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.modules.decoder.rst b/docs/source/fastNLP.modules.decoder.rst index 60706b06..5e467b98 100644 --- a/docs/source/fastNLP.modules.decoder.rst +++ b/docs/source/fastNLP.modules.decoder.rst @@ -1,6 +1,11 @@ fastNLP.modules.decoder package =============================== +.. automodule:: fastNLP.modules.decoder + :members: + :undoc-members: + :show-inheritance: + Submodules ---------- @@ -29,10 +34,3 @@ fastNLP.modules.decoder.utils module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.modules.decoder - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.modules.encoder.rst b/docs/source/fastNLP.modules.encoder.rst index 4cc0b8ab..ff048be7 100644 --- a/docs/source/fastNLP.modules.encoder.rst +++ b/docs/source/fastNLP.modules.encoder.rst @@ -1,13 +1,26 @@ fastNLP.modules.encoder package =============================== +.. automodule:: fastNLP.modules.encoder + :members: + :undoc-members: + :show-inheritance: + Submodules ---------- -fastNLP.modules.encoder.char_embedding module ---------------------------------------------- +fastNLP.modules.encoder.bert module +----------------------------------- -.. automodule:: fastNLP.modules.encoder.char_embedding +.. automodule:: fastNLP.modules.encoder.bert + :members: + :undoc-members: + :show-inheritance: + +fastNLP.modules.encoder.char\_encoder module +-------------------------------------------- + +.. automodule:: fastNLP.modules.encoder.char_encoder :members: :undoc-members: :show-inheritance: @@ -20,8 +33,8 @@ fastNLP.modules.encoder.conv module :undoc-members: :show-inheritance: -fastNLP.modules.encoder.conv_maxpool module -------------------------------------------- +fastNLP.modules.encoder.conv\_maxpool module +-------------------------------------------- .. automodule:: fastNLP.modules.encoder.conv_maxpool :members: @@ -52,16 +65,16 @@ fastNLP.modules.encoder.lstm module :undoc-members: :show-inheritance: -fastNLP.modules.encoder.masked_rnn module ------------------------------------------ +fastNLP.modules.encoder.masked\_rnn module +------------------------------------------ .. automodule:: fastNLP.modules.encoder.masked_rnn :members: :undoc-members: :show-inheritance: -fastNLP.modules.encoder.star_transformer module ------------------------------------------------ +fastNLP.modules.encoder.star\_transformer module +------------------------------------------------ .. automodule:: fastNLP.modules.encoder.star_transformer :members: @@ -76,8 +89,8 @@ fastNLP.modules.encoder.transformer module :undoc-members: :show-inheritance: -fastNLP.modules.encoder.variational_rnn module ----------------------------------------------- +fastNLP.modules.encoder.variational\_rnn module +----------------------------------------------- .. automodule:: fastNLP.modules.encoder.variational_rnn :members: @@ -85,10 +98,3 @@ fastNLP.modules.encoder.variational_rnn module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.modules.encoder - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.modules.rst b/docs/source/fastNLP.modules.rst index 53cc19a0..5884e655 100644 --- a/docs/source/fastNLP.modules.rst +++ b/docs/source/fastNLP.modules.rst @@ -1,6 +1,11 @@ fastNLP.modules package ======================= +.. automodule:: fastNLP.modules + :members: + :undoc-members: + :show-inheritance: + Subpackages ----------- @@ -21,8 +26,8 @@ fastNLP.modules.dropout module :undoc-members: :show-inheritance: -fastNLP.modules.other_modules module ------------------------------------- +fastNLP.modules.other\_modules module +------------------------------------- .. automodule:: fastNLP.modules.other_modules :members: @@ -38,10 +43,3 @@ fastNLP.modules.utils module :show-inheritance: -Module contents ---------------- - -.. automodule:: fastNLP.modules - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/source/fastNLP.rst b/docs/source/fastNLP.rst index 6348c9a6..f5247748 100644 --- a/docs/source/fastNLP.rst +++ b/docs/source/fastNLP.rst @@ -1,6 +1,11 @@ fastNLP package =============== +.. automodule:: fastNLP + :members: + :undoc-members: + :show-inheritance: + Subpackages ----------- @@ -8,15 +13,9 @@ Subpackages fastNLP.api fastNLP.automl + fastNLP.component fastNLP.core fastNLP.io fastNLP.models fastNLP.modules -Module contents ---------------- - -.. automodule:: fastNLP - :members: - :undoc-members: - :show-inheritance: