class_docstr: **LSTM** 的 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 num_layers: LSTM 的层数
  :param hidden_size: 隐藏层大小, 该值也被认为是 ``encoder`` 的输出维度大小
  :param dropout: 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``。
  :param attention: 是否使用attention
class_docstr_tok: ["*","*","LSTM","*","*","\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","num_layers",":","LSTM","\u7684\u5c42\u6570",":","param","hidden_size",":","\u9690\u85cf\u5c42\u5927\u5c0f",",","\u8be5\u503c\u4e5f\u88ab\u8ba4\u4e3a\u662f","``","encoder","``","\u7684\u8f93\u51fa\u7ef4\u5ea6\u5927\u5c0f",":","param","dropout",":","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",":","param","attention",":","\u662f\u5426\u4f7f\u7528attention"]
docstr: :param encoder_output: ``encoder`` 的输出，可以有两种情况：
          
          - 输入一个 :class:`tuple`，包含三个内容 ``(encoder_output, (hidden, cell))``，其中 ``encoder_output`` 形状为
            ``[batch_size, max_len, hidden_size]``， ``hidden`` 形状为 ``[batch_size, hidden_size]``， ``cell`` 形状为
            ``[batch_size, hidden_size]`` ，一般使用 :class:`~fastNLP.modules.torch.encoder.LSTMSeq2SeqEncoder` 最后一层的
            ``hidden state`` 和 ``cell state`` 来赋值这两个值。
          - 只有形状为 ``[batch_size, max_len, hidden_size]`` 的 ``encoder_output``, 这种情况下 ``hidden`` 和 ``cell``
            使用 **0** 初始化。
  :param encoder_mask: ``[batch_size, max_len]]``，为 **0** 的位置是 padding, 用来指示输入中哪些不需要 attend 。
  :return:
docstr_tok: [":","param","encoder_output",":","``","encoder","``","\u7684\u8f93\u51fa\uff0c\u53ef\u4ee5\u6709\u4e24\u79cd\u60c5\u51b5\uff1a","-","\u8f93\u5165\u4e00\u4e2a",":","class",":","`","tuple","`","\uff0c\u5305\u542b\u4e09\u4e2a\u5185\u5bb9","``","(","encoder_output",",","(","hidden",",","cell",")",")","``","\uff0c\u5176\u4e2d","``","encoder_output","``","\u5f62\u72b6\u4e3a","``","[","batch_size",",","max_len",",","hidden_size","]","``","\uff0c","``","hidden","``","\u5f62\u72b6\u4e3a","``","[","batch_size",",","hidden_size","]","``","\uff0c","``","cell","``","\u5f62\u72b6\u4e3a","``","[","batch_size",",","hidden_size","]","``","\uff0c\u4e00\u822c\u4f7f\u7528",":","class",":","`","~fastNLP.modules.torch.encoder.LSTMSeq2SeqEncoder","`","\u6700\u540e\u4e00\u5c42\u7684","``","hidden","state","``","\u548c","``","cell","state","``","\u6765\u8d4b\u503c\u8fd9\u4e24\u4e2a\u503c\u3002","-","\u53ea\u6709\u5f62\u72b6\u4e3a","``","[","batch_size",",","max_len",",","hidden_size","]","``","\u7684","``","encoder_output","``",",","\u8fd9\u79cd\u60c5\u51b5\u4e0b","``","hidden","``","\u548c","``","cell","``","\u4f7f\u7528","*","*","0","*","*","\u521d\u59cb\u5316\u3002",":","param","encoder_mask",":","``","[","batch_size",",","max_len","]","]","``","\uff0c\u4e3a","*","*","0","*","*","\u7684\u4f4d\u7f6e\u662f","padding",",","\u7528\u6765\u6307\u793a\u8f93\u5165\u4e2d\u54ea\u4e9b\u4e0d\u9700\u8981","attend","\u3002",":","return",":"]
code: def init_state(
      self, encoder_output, encoder_mask: torch.ByteTensor
  ) -> LSTMState:
      """
  
      :param encoder_output: ``encoder`` 的输出，可以有两种情况：
  
              - 输入一个 :class:`tuple`，包含三个内容 ``(encoder_output, (hidden, cell))``，其中 ``encoder_output`` 形状为
                ``[batch_size, max_len, hidden_size]``， ``hidden`` 形状为 ``[batch_size, hidden_size]``， ``cell`` 形状为
                ``[batch_size, hidden_size]`` ，一般使用 :class:`~fastNLP.modules.torch.encoder.LSTMSeq2SeqEncoder` 最后一层的
                ``hidden state`` 和 ``cell state`` 来赋值这两个值。
              - 只有形状为 ``[batch_size, max_len, hidden_size]`` 的 ``encoder_output``, 这种情况下 ``hidden`` 和 ``cell``
                使用 **0** 初始化。
      :param encoder_mask: ``[batch_size, max_len]]``，为 **0** 的位置是 padding, 用来指示输入中哪些不需要 attend 。
      :return:
      """
      if not isinstance(encoder_output, torch.Tensor):
          encoder_output, (hidden, cell) = encoder_output
      else:
          hidden = cell = None
      assert encoder_output.ndim == 3
      assert encoder_mask.size() == encoder_output.size()[:2]
      assert encoder_output.size(-1) == self.hidden_size, (
          "The dimension of encoder outputs should be the same with "
          "the hidden_size."
      )
  
      t = [hidden, cell]
      for idx in range(2):
          v = t[idx]
          if v is None:
              v = encoder_output.new_zeros(
                  self.num_layers,
                  encoder_output.size(0),
                  self.hidden_size,
              )
          else:
              assert v.dim() == 2
              assert v.size(-1) == self.hidden_size
              v = v[None].repeat(
                  self.num_layers, 1, 1
              )  # num_layers x bsz x hidden_size
          t[idx] = v
  
      state = LSTMState(encoder_output, encoder_mask, t[0], t[1])
  
      return state
  
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 3 for calling the LSTMSeq2SeqDecoder obj's underlying member method code with example usage: obj.init_state(encoder_output, encoder_mask) and returns: state