Browse Source

modules入口的介绍和dropout的文档

tags/v0.4.10
ChenXin 6 years ago
parent
commit
a09cf518d7
2 changed files with 15 additions and 18 deletions
  1. +13
    -14
      fastNLP/modules/__init__.py
  2. +2
    -4
      fastNLP/modules/dropout.py

+ 13
- 14
fastNLP/modules/__init__.py View File

@@ -1,22 +1,19 @@
""" """
大部分用于的 NLP 任务神经网络都可以看做由编码 :mod:`~fastNLP.modules.encoder` 、
解码 :mod:`~fastNLP.modules.decoder` 两种模块组成。


.. image:: figures/text_classification.png .. image:: figures/text_classification.png


:mod:`~fastNLP.modules` 中实现了 fastNLP 提供的诸多模块组件,可以帮助用户快速搭建自己所需的网络。
两种模块的功能和常见组件如下:
大部分用于的 NLP 任务神经网络都可以看做由 :mod:`embedding<fastNLP.embeddings>` 、 :mod:`~fastNLP.modules.encoder` 、
:mod:`~fastNLP.modules.decoder` 三种模块组成。 本模块中实现了 fastNLP 提供的诸多模块组件,
可以帮助用户快速搭建自己所需的网络。几种模块的功能和常见组件如下:

.. csv-table::
:header: "类型", "功能", "常见组件"

"embedding", 参见 :doc:`fastNLP.embeddings` , "Elmo, Bert"
"encoder", "将输入编码为具有表示能力的向量", "CNN, LSTM, Transformer"
"decoder", "将具有某种表示意义的向量解码为需要的输出形式 ", "MLP, CRF"
"其它", "配合其它组件使用的组件", "Dropout"


+-----------------------+-----------------------+-----------------------+
| module type | functionality | example |
+=======================+=======================+=======================+
| encoder | 将输入编码为具有具 | embedding, RNN, CNN, |
| | 有表示能力的向量 | transformer |
+-----------------------+-----------------------+-----------------------+
| decoder | 将具有某种表示意义的 | MLP, CRF |
| | 向量解码为需要的输出 | |
| | 形式 | |
+-----------------------+-----------------------+-----------------------+


""" """
__all__ = [ __all__ = [
@@ -40,6 +37,8 @@ __all__ = [
"ConditionalRandomField", "ConditionalRandomField",
"viterbi_decode", "viterbi_decode",
"allowed_transitions", "allowed_transitions",

"TimestepDropout",
] ]


from . import decoder from . import decoder


+ 2
- 4
fastNLP/modules/dropout.py View File

@@ -5,10 +5,8 @@ import torch


class TimestepDropout(torch.nn.Dropout): class TimestepDropout(torch.nn.Dropout):
""" """
别名::class:`fastNLP.modules.TimestepDropout`

接受的参数shape为``[batch_size, num_timesteps, embedding_dim)]`` 使用同一个mask(shape为``(batch_size, embedding_dim)``)
在每个timestamp上做dropout。
传入参数的shape为 ``(batch_size, num_timesteps, embedding_dim)``
使用同一个shape为 ``(batch_size, embedding_dim)`` 的mask在每个timestamp上做dropout。
""" """
def forward(self, x): def forward(self, x):


Loading…
Cancel
Save