class_docstr: **Transformer** 的 Decoder
  
  :param embed: ``decoder`` 输入的 embedding，支持以下几种输入类型：
  
          - ``tuple(num_embedings, embedding_dim)``，即 embedding 的大小和每个词的维度，此时将随机初始化一个 :class:`torch.nn.Embedding` 实例；
          - :class:`torch.nn.Embedding` 或 **fastNLP** 的 ``Embedding`` 对象，此时就以传入的对象作为 embedding；
          - :class:`numpy.ndarray` ，将使用传入的 ndarray 作为 Embedding 初始化；
          - :class:`torch.Tensor`，此时将使用传入的值作为 Embedding 初始化；
  :param pos_embed: 位置 embedding
  :param d_model: 输入、输出的维度
  :param num_layers: :class:`TransformerSeq2SeqDecoderLayer` 的层数
  :param n_head: **多头注意力** head 的数目，需要能被 ``d_model`` 整除
  :param dim_ff: FFN 中间映射的维度
  :param dropout: :class:`~fastNLP.modules.torch.decoder.SelfAttention` 和 FFN 中的 dropout 的大小
  :param bind_decoder_input_output_embed: ``decoder`` 的输出 embedding 是否与其输入 embedding 是一样的权重（即为同一个），若 ``embed`` 为 
      :class:`~fastNLP.embeddings.StaticEmbedding`，则 ``StaticEmbedding`` 的 ``vocab`` 不能包含 ``no_create_entry`` 的 token ，同时
      ``StaticEmbedding`` 初始化时 ``lower`` 为 ``False``，``min_freq=1``。
class_docstr_tok: ["*","*","Transformer","*","*","\u7684","Decoder",":","param","embed",":","``","decoder","``","\u8f93\u5165\u7684","embedding\uff0c\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u8f93\u5165\u7c7b\u578b\uff1a","-","``","tuple","(","num_embedings",",","embedding_dim",")","``","\uff0c\u5373","embedding","\u7684\u5927\u5c0f\u548c\u6bcf\u4e2a\u8bcd\u7684\u7ef4\u5ea6\uff0c\u6b64\u65f6\u5c06\u968f\u673a\u521d\u59cb\u5316\u4e00\u4e2a",":","class",":","`","torch.nn.Embedding","`","\u5b9e\u4f8b\uff1b","-",":","class",":","`","torch.nn.Embedding","`","\u6216","*","*","fastNLP","*","*","\u7684","``","Embedding","``","\u5bf9\u8c61\uff0c\u6b64\u65f6\u5c31\u4ee5\u4f20\u5165\u7684\u5bf9\u8c61\u4f5c\u4e3a","embedding\uff1b","-",":","class",":","`","numpy.ndarray","`","\uff0c\u5c06\u4f7f\u7528\u4f20\u5165\u7684","ndarray","\u4f5c\u4e3a","Embedding","\u521d\u59cb\u5316\uff1b","-",":","class",":","`","torch.Tensor","`","\uff0c\u6b64\u65f6\u5c06\u4f7f\u7528\u4f20\u5165\u7684\u503c\u4f5c\u4e3a","Embedding","\u521d\u59cb\u5316\uff1b",":","param","pos_embed",":","\u4f4d\u7f6e","embedding",":","param","d_model",":","\u8f93\u5165\u3001\u8f93\u51fa\u7684\u7ef4\u5ea6",":","param","num_layers",":",":","class",":","`","TransformerSeq2SeqDecoderLayer","`","\u7684\u5c42\u6570",":","param","n_head",":","*","*","\u591a\u5934\u6ce8\u610f\u529b","*","*","head","\u7684\u6570\u76ee\uff0c\u9700\u8981\u80fd\u88ab","``","d_model","``","\u6574\u9664",":","param","dim_ff",":","FFN","\u4e2d\u95f4\u6620\u5c04\u7684\u7ef4\u5ea6",":","param","dropout",":",":","class",":","`","~fastNLP.modules.torch.decoder.SelfAttention","`","\u548c","FFN","\u4e2d\u7684","dropout","\u7684\u5927\u5c0f",":","param","bind_decoder_input_output_embed",":","``","decoder","``","\u7684\u8f93\u51fa","embedding","\u662f\u5426\u4e0e\u5176\u8f93\u5165","embedding","\u662f\u4e00\u6837\u7684\u6743\u91cd\uff08\u5373\u4e3a\u540c\u4e00\u4e2a\uff09\uff0c\u82e5","``","embed","``","\u4e3a",":","class",":","`","~fastNLP.embeddings.StaticEmbedding","`","\uff0c\u5219","``","StaticEmbedding","``","\u7684","``","vocab","``","\u4e0d\u80fd\u5305\u542b","``","no_create_entry","``","\u7684","token","\uff0c\u540c\u65f6","``","StaticEmbedding","``","\u521d\u59cb\u5316\u65f6","``","lower","``","\u4e3a","``","False","``","\uff0c","``","min_freq=1","``","\u3002"]
code: def _get_triangle_mask(tokens):
      tensor = tokens.new_ones(tokens.size(1), tokens.size(1))
      return torch.tril(tensor).byte()
  
imports: from typing import Union, Tuple
  import math
  import torch
  from torch import nn
  import torch.nn.functional
  from ..attention import AttentionLayer, MultiHeadAttention
  from ....embeddings.torch.utils import get_embeddings
  from ....embeddings.torch.static_embedding import StaticEmbedding
  from .seq2seq_state import State, LSTMState, TransformerState
label_desc: Use image node_id 4 for calling the TransformerSeq2SeqDecoder obj's underlying member method code with example usage: obj._get_triangle_mask(tokens) and returns: torch