class_docstr: **Sequence-to-Sequence Decoder** 的基类。一定需要实现 :meth:`forward` 和 :meth:`decode` 函数，剩下的函数根据需要实现。每个 ``Seq2SeqDecoder`` 都应该有相应的
  :class:`~fastNLP.modules.torch.decoder.State` 对象用来承载该 ``Decoder`` 所需要的 ``Encoder`` 输出、``Decoder`` 需要记录的历史信（例如 :class:`~fastNLP.modules.torch.encoder.LSTM`
  的 hidden 信息）。
class_docstr_tok: ["*","*","Sequence-to-Sequence","Decoder","*","*","\u7684\u57fa\u7c7b\u3002\u4e00\u5b9a\u9700\u8981\u5b9e\u73b0",":","meth",":","`","forward","`","\u548c",":","meth",":","`","decode","`","\u51fd\u6570\uff0c\u5269\u4e0b\u7684\u51fd\u6570\u6839\u636e\u9700\u8981\u5b9e\u73b0\u3002\u6bcf\u4e2a","``","Seq2SeqDecoder","``","\u90fd\u5e94\u8be5\u6709\u76f8\u5e94\u7684",":","class",":","`","~fastNLP.modules.torch.decoder.State","`","\u5bf9\u8c61\u7528\u6765\u627f\u8f7d\u8be5","``","Decoder","``","\u6240\u9700\u8981\u7684","``","Encoder","``","\u8f93\u51fa\u3001","``","Decoder","``","\u9700\u8981\u8bb0\u5f55\u7684\u5386\u53f2\u4fe1\uff08\u4f8b\u5982",":","class",":","`","~fastNLP.modules.torch.encoder.LSTM","`","\u7684","hidden","\u4fe1\u606f\uff09\u3002"]
docstr: 初始化一个 :class:`~fastNLP.modules.torch.decoder.State` 对象，用来记录 ``encoder`` 的输出以及 ``decode`` 已经完成的部分。
  
  :param encoder_output: 如果不为 ``None`` ，内部元素需要为 :class:`torch.Tensor`，默认其中第一维是 batch_size
      维度
  :param encoder_mask: 如果不为 ``None``，内部元素需要为 :class:`torch.Tensor`，默认其中第一维是 batch_size
      维度
  :return: 一个 :class:`~fastNLP.modules.torch.decoder.State` 对象，记录了 ``encoder`` 的输出
docstr_tok: ["\u521d\u59cb\u5316\u4e00\u4e2a",":","class",":","`","~fastNLP.modules.torch.decoder.State","`","\u5bf9\u8c61\uff0c\u7528\u6765\u8bb0\u5f55","``","encoder","``","\u7684\u8f93\u51fa\u4ee5\u53ca","``","decode","``","\u5df2\u7ecf\u5b8c\u6210\u7684\u90e8\u5206\u3002",":","param","encoder_output",":","\u5982\u679c\u4e0d\u4e3a","``","None","``","\uff0c\u5185\u90e8\u5143\u7d20\u9700\u8981\u4e3a",":","class",":","`","torch.Tensor","`","\uff0c\u9ed8\u8ba4\u5176\u4e2d\u7b2c\u4e00\u7ef4\u662f","batch_size","\u7ef4\u5ea6",":","param","encoder_mask",":","\u5982\u679c\u4e0d\u4e3a","``","None","``","\uff0c\u5185\u90e8\u5143\u7d20\u9700\u8981\u4e3a",":","class",":","`","torch.Tensor","`","\uff0c\u9ed8\u8ba4\u5176\u4e2d\u7b2c\u4e00\u7ef4\u662f","batch_size","\u7ef4\u5ea6",":","return",":","\u4e00\u4e2a",":","class",":","`","~fastNLP.modules.torch.decoder.State","`","\u5bf9\u8c61\uff0c\u8bb0\u5f55\u4e86","``","encoder","``","\u7684\u8f93\u51fa"]
code: def init_state(
      self,
      encoder_output: Union[torch.Tensor, list, tuple],
      encoder_mask: Union[torch.Tensor, list, tuple],
  ):
      """
      初始化一个 :class:`~fastNLP.modules.torch.decoder.State` 对象，用来记录 ``encoder`` 的输出以及 ``decode`` 已经完成的部分。
  
      :param encoder_output: 如果不为 ``None`` ，内部元素需要为 :class:`torch.Tensor`，默认其中第一维是 batch_size
          维度
      :param encoder_mask: 如果不为 ``None``，内部元素需要为 :class:`torch.Tensor`，默认其中第一维是 batch_size
          维度
      :return: 一个 :class:`~fastNLP.modules.torch.decoder.State` 对象，记录了 ``encoder`` 的输出
      """
      state = State(encoder_output, encoder_mask)
      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 4 for calling the Seq2SeqDecoder obj's underlying member method code with example usage: obj.init_state(encoder_output, encoder_mask) and returns: state