mindspore/docs/api/api_python/nn/mindspore.nn.TransformerEnc...

25 lines
1.6 KiB
ReStructuredText
Raw Normal View History

2023-02-17 10:12:26 +08:00
mindspore.nn.TransformerEncoderLayer
========================================
.. py:class:: mindspore.nn.TransformerEncoderLayer(d_model: int, nhead: int, dim_feedforward: int = 2048, dropout: float = 0.1, activation: Union[str, Cell] = 'relu', layer_norm_eps: float = 1e-5, batch_first: bool = False, norm_first: bool = False)
Transformer的编码器层。Transformer编码器的单层实现包括MultiheadAttention层和FeedForward层。
参数:
- **d_model** (int) - 输入的特征数。
- **nhead** (int) - 注意力头的数量。
- **dim_feedforward** (int) - FeedForward层的维数。默认2048。
- **dropout** (float) - 随机丢弃比例。默认0.1。
- **activation** (str, Cell) - 中间层的激活函数,可以输入字符串、函数接口或激活函数层实例。支持'relu''gelu'。默认:'relu'。
- **layer_norm_eps** (float) - LayerNorm层的eps值默认1e-5。
- **batch_first** (bool) - 如果为 ``True`` 则输入输出Shape为(batch, seq, feature)反之Shape为(seq, batch, feature)。默认: ``False``
- **norm_first** (bool) - 如果为 ``True`` 则LayerNorm层位于MultiheadAttention层和FeedForward层之前反之位于其后。默认 ``False``
输入:
- **src** (Tensor) - 源序列。
- **src_mask** (Tensor) - 源序列的掩码矩阵 (可选)。默认None。
- **src_key_padding_mask** (Tensor) - 源序列Key矩阵的掩码矩阵 (可选)。默认None。
输出:
Tensor。