mindspore/docs/api/api_python/nn/mindspore.nn.TransformerDec...

23 lines
2.1 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.TransformerDecoder
========================================
.. py:class:: mindspore.nn.TransformerDecoder(decoder_layer, num_layers, norm=None)
Transformer的解码器模块多层 :class:`mindspore.nn.TransformerDecoderLayer` 的堆叠包括Self Attention层、MultiheadAttention层和FeedForward层。
参数:
- **decoder_layer** (Cell) - :class:`mindspore.nn.TransformerDecoderLayer` 的实例。
- **num_layers** (int) - 解码器层数。
- **norm** (Cell, 可选) - 层标准化模块。默认值: ``None``
输入:
- **tgt** (Tensor) - 目标序列。如果目标序列没有batch则shape为 :math:`(T, E)` 。否则,如果 :class:`mindspore.nn.TransformerDecoderLayer``batch_first=False` 则shape为 :math:`(T, N, E)` ;如果 `batch_first=True` 则shape为 :math:`(N, T, E)`。其中, :math:`(T)` 是目标序列的长度, :math:`(N)` 是batch个数 :math:`(E)` 是特性个数。数据类型为float16、float32或者float64。
- **memory** (Tensor) - TransformerEncoder的最后一层输出序列。数据类型float16、float32或者float64。
- **tgt_mask** (Tensor, 可选) - 目标序列的掩码矩阵。shape为 :math:`(T, T)`:math:`(N*nhead, T, T)` 。其中 `nhead`:class:`mindspore.nn.TransformerDecoderLayer` 中的 `nhead` 参数。数据类型为float16、float32、float64或者bool。默认值 ``None``
- **memory_mask** (Tensor, 可选) - memory序列的掩码矩阵。shape为 :math:`(T, S)` 。数据类型为float16、float32、float64或者bool。默认值``None``
- **tgt_key_padding_mask** (Tensor, 可选) - 目标序列Key矩阵的掩码矩阵。shape为 :math:`(T)` 。数据类型为float16、float32、float64或者bool。默认值``None``
- **memory_key_padding_mask** (Tensor, 可选) - memory序列Key矩阵的掩码矩阵。如果目标序列没有batchshape为 :math:`(S)` 否则shape为 :math:`(N, S)` 。数据类型为float16、float32、float64或者bool。默认值 ``None``
输出:
Tensor。Tensor的shape和dtype与 `tgt` 一致。