From 208cf5facb8b5644516ced00df3251100c8275d0 Mon Sep 17 00:00:00 2001 From: ChenXin Date: Mon, 13 May 2019 10:08:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=20modules=20?= =?UTF-8?q?=E5=92=8C=20models=20=E5=BC=80=E7=AF=87=E4=BB=8B=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/index.rst | 6 ++-- fastNLP/models/__init__.py | 8 ++++-- fastNLP/modules/__init__.py | 40 +++++++++++++++++++++++--- fastNLP/modules/aggregator/__init__.py | 9 +++++- fastNLP/modules/decoder/__init__.py | 8 +++++- fastNLP/modules/encoder/__init__.py | 10 ++++--- 6 files changed, 66 insertions(+), 15 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index d77ae1c8..554b1afc 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -15,12 +15,12 @@ fastNLP 是一款轻量级的 NLP 处理套件。你既可以使用它快速地 内置组件 ------------ -大部分用于的 NLP 任务神经网络都可以看做由编码(encoder)、聚合(aggregator)、解码(decoder)三中模块组成。 +大部分用于的 NLP 任务神经网络都可以看做由编码(encoder)、聚合(aggregator)、解码(decoder)三种模块组成。 .. image:: figures/text_classification.png -fastNLP 在 :mod:`~fastNLP.modules` 模块中内置了三个模块的诸多组件,可以帮助用户快速搭建自己所需的网络。 -三个模块的功能和常见组件如下: +fastNLP 在 :mod:`~fastNLP.modules` 模块中内置了三种模块的诸多组件,可以帮助用户快速搭建自己所需的网络。 +三种模块的功能和常见组件如下: +-----------------------+-----------------------+-----------------------+ | module type | functionality | example | diff --git a/fastNLP/models/__init__.py b/fastNLP/models/__init__.py index bad96cf9..66af3a46 100644 --- a/fastNLP/models/__init__.py +++ b/fastNLP/models/__init__.py @@ -1,6 +1,10 @@ """ -使用 fastNLP 实现的一系列常见模型,具体有: -TODO 详细介绍的表格,与主页相对应 +fastNLP 在 :mod:`~fastNLP.models` 模块中内置了如 :class:`~fastNLP.models.CNNText` 、 +:class:`~fastNLP.models.SeqLabeling` 等完整的模型,以供用户直接使用。 + +.. todo:: + 这些模型的介绍(与主页一致) + """ __all__ = ["CNNText", "SeqLabeling", "ESIM", "STSeqLabel", "AdvSeqLabel", "STNLICls", "STSeqCls"] diff --git a/fastNLP/modules/__init__.py b/fastNLP/modules/__init__.py index 4022de9d..53d44f47 100644 --- a/fastNLP/modules/__init__.py +++ b/fastNLP/modules/__init__.py @@ -1,10 +1,25 @@ """ -modules 模块是 fastNLP 的重要组成部分,它实现了神经网络构建中常见的组件, -具体包括 TODO +大部分用于的 NLP 任务神经网络都可以看做由编码 :mod:`~fastNLP.modules.encoder` 、 +聚合 :mod:`~fastNLP.modules.aggregator` 、解码 :mod:`~fastNLP.modules.decoder` 三种模块组成。 -可以和 PyTorch 结合使用?TODO +.. image:: figures/text_classification.png -TODO __all__ 里面多暴露一些 +:mod:`~fastNLP.modules` 中实现了 fastNLP 提供的诸多模块组件,可以帮助用户快速搭建自己所需的网络。 +三种模块的功能和常见组件如下: + ++-----------------------+-----------------------+-----------------------+ +| module type | functionality | example | ++=======================+=======================+=======================+ +| encoder | 将输入编码为具有具 | embedding, RNN, CNN, | +| | 有表示能力的向量 | transformer | ++-----------------------+-----------------------+-----------------------+ +| aggregator | 从多个向量中聚合信息 | self-attention, | +| | | max-pooling | ++-----------------------+-----------------------+-----------------------+ +| decoder | 将具有某种表示意义的 | MLP, CRF | +| | 向量解码为需要的输出 | | +| | 形式 | | ++-----------------------+-----------------------+-----------------------+ """ from . import aggregator @@ -16,3 +31,20 @@ from .dropout import TimestepDropout from .encoder import * from .utils import get_embeddings +__all__ = [ + "LSTM", + "Embedding", + "ConvMaxpool", + "BertModel", + + "MaxPool", + "MaxPoolWithMask", + "AvgPool", + "MultiHeadAttention", + "BiAttention", + + "MLP", + "ConditionalRandomField", + "viterbi_decode", + "allowed_transitions", +] \ No newline at end of file diff --git a/fastNLP/modules/aggregator/__init__.py b/fastNLP/modules/aggregator/__init__.py index bfb7579b..4a76cf5b 100644 --- a/fastNLP/modules/aggregator/__init__.py +++ b/fastNLP/modules/aggregator/__init__.py @@ -1,7 +1,14 @@ -__all__ = ["MaxPool", "MaxPoolWithMask", "AvgPool", "MultiHeadAttention", "BiAttention"] from .pooling import MaxPool from .pooling import MaxPoolWithMask from .pooling import AvgPool from .pooling import MeanPoolWithMask from .attention import MultiHeadAttention, BiAttention +__all__ = [ + "MaxPool", + "MaxPoolWithMask", + "AvgPool", + + "MultiHeadAttention", + "BiAttention" +] diff --git a/fastNLP/modules/decoder/__init__.py b/fastNLP/modules/decoder/__init__.py index 84763e03..516b687a 100644 --- a/fastNLP/modules/decoder/__init__.py +++ b/fastNLP/modules/decoder/__init__.py @@ -1,5 +1,11 @@ -__all__ = ["MLP", "ConditionalRandomField", "viterbi_decode", "allowed_transitions"] from .CRF import ConditionalRandomField from .MLP import MLP from .utils import viterbi_decode from .CRF import allowed_transitions + +__all__ = [ + "MLP", + "ConditionalRandomField", + "viterbi_decode", + "allowed_transitions" +] diff --git a/fastNLP/modules/encoder/__init__.py b/fastNLP/modules/encoder/__init__.py index a1cd910b..67f69850 100644 --- a/fastNLP/modules/encoder/__init__.py +++ b/fastNLP/modules/encoder/__init__.py @@ -3,7 +3,9 @@ from .embedding import Embedding from .lstm import LSTM from .bert import BertModel -__all__ = ["LSTM", - "Embedding", - "ConvMaxpool", - "BertModel"] +__all__ = [ + "LSTM", + "Embedding", + "ConvMaxpool", + "BertModel" +]