class_docstr: 使用 :class:`~fastNLP.modules.torch.encoder.LSTMSeq2SeqEncoder` 和 :class:`~fastNLP.modules.torch.decoder.LSTMSeq2SeqDecoder` 的
  :class:`Seq2SeqModel`，通过 :meth:`build_model` 方法初始化。
docstr: :param src_embed: source 的 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 tgt_embed: target 的 embedding，如果 ``bind_encoder_decoder_embed``
      为 ``True`` ，则不要输入该值，支持以下几种输入类型：
  
          - ``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: ``encoder`` 和 ``decoder`` 的层数
  :param hidden_size: ``encoder`` 和 ``decoder`` 的隐藏层大小
  :param dropout: 每层之间的 Dropout 的大小
  :param bidirectional: ``encoder`` 是否使用 **双向LSTM**
  :param attention: 是否在 ``decoder`` 中使用 attention 来添加 ``encoder`` 在所有时刻的状态
  :param bind_encoder_decoder_embed: 是否对 ``encoder`` 和 ``decoder`` 使用相同的 embedding
  :param bind_decoder_input_output_embed: ``decoder`` 的输出 embedding 是否与其输入 embedding 是一样的权重
  :return: :class:`LSTMSeq2SeqModel` 模型
docstr_tok: [":","param","src_embed",":","source","\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","tgt_embed",":","target","\u7684","embedding\uff0c\u5982\u679c","``","bind_encoder_decoder_embed","``","\u4e3a","``","True","``","\uff0c\u5219\u4e0d\u8981\u8f93\u5165\u8be5\u503c\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",":","``","encoder","``","\u548c","``","decoder","``","\u7684\u5c42\u6570",":","param","hidden_size",":","``","encoder","``","\u548c","``","decoder","``","\u7684\u9690\u85cf\u5c42\u5927\u5c0f",":","param","dropout",":","\u6bcf\u5c42\u4e4b\u95f4\u7684","Dropout","\u7684\u5927\u5c0f",":","param","bidirectional",":","``","encoder","``","\u662f\u5426\u4f7f\u7528","*","*","\u53cc\u5411LSTM","*","*",":","param","attention",":","\u662f\u5426\u5728","``","decoder","``","\u4e2d\u4f7f\u7528","attention","\u6765\u6dfb\u52a0","``","encoder","``","\u5728\u6240\u6709\u65f6\u523b\u7684\u72b6\u6001",":","param","bind_encoder_decoder_embed",":","\u662f\u5426\u5bf9","``","encoder","``","\u548c","``","decoder","``","\u4f7f\u7528\u76f8\u540c\u7684","embedding",":","param","bind_decoder_input_output_embed",":","``","decoder","``","\u7684\u8f93\u51fa","embedding","\u662f\u5426\u4e0e\u5176\u8f93\u5165","embedding","\u662f\u4e00\u6837\u7684\u6743\u91cd",":","return",":",":","class",":","`","LSTMSeq2SeqModel","`","\u6a21\u578b"]
code: def build_model(
      cls,
      src_embed,
      tgt_embed=None,
      num_layers: int = 3,
      hidden_size: int = 400,
      dropout: float = 0.3,
      bidirectional: bool = True,
      attention: bool = True,
      bind_encoder_decoder_embed: bool = False,
      bind_decoder_input_output_embed: bool = True,
  ):
      """
  
      :param src_embed: source 的 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 tgt_embed: target 的 embedding，如果 ``bind_encoder_decoder_embed``
          为 ``True`` ，则不要输入该值，支持以下几种输入类型：
  
              - ``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: ``encoder`` 和 ``decoder`` 的层数
      :param hidden_size: ``encoder`` 和 ``decoder`` 的隐藏层大小
      :param dropout: 每层之间的 Dropout 的大小
      :param bidirectional: ``encoder`` 是否使用 **双向LSTM**
      :param attention: 是否在 ``decoder`` 中使用 attention 来添加 ``encoder`` 在所有时刻的状态
      :param bind_encoder_decoder_embed: 是否对 ``encoder`` 和 ``decoder`` 使用相同的 embedding
      :param bind_decoder_input_output_embed: ``decoder`` 的输出 embedding 是否与其输入 embedding 是一样的权重
      :return: :class:`LSTMSeq2SeqModel` 模型
      """
      if bind_encoder_decoder_embed and tgt_embed is not None:
          raise RuntimeError(
              "If you set `bind_encoder_decoder_embed=True`, please do not provide `tgt_embed`."
          )
  
      src_embed = get_embeddings(src_embed)
  
      if bind_encoder_decoder_embed:
          tgt_embed = src_embed
      else:
          assert (
              tgt_embed is not None
          ), "You need to pass `tgt_embed` when `bind_encoder_decoder_embed=False`"
          tgt_embed = get_embeddings(tgt_embed)
  
      encoder = LSTMSeq2SeqEncoder(
          embed=src_embed,
          num_layers=num_layers,
          hidden_size=hidden_size,
          dropout=dropout,
          bidirectional=bidirectional,
      )
      decoder = LSTMSeq2SeqDecoder(
          embed=tgt_embed,
          num_layers=num_layers,
          hidden_size=hidden_size,
          dropout=dropout,
          bind_decoder_input_output_embed=bind_decoder_input_output_embed,
          attention=attention,
      )
      return cls(encoder, decoder)
  
imports: import torch
  from torch import nn
  import torch.nn.functional
  from fastNLP import seq_len_to_mask
  from ...embeddings.torch.utils import get_embeddings
  from ...embeddings.torch.utils import get_sinusoid_encoding_table
  from ...modules.torch.decoder.seq2seq_decoder import Seq2SeqDecoder, TransformerSeq2SeqDecoder, LSTMSeq2SeqDecoder
  from ...modules.torch.encoder.seq2seq_encoder import Seq2SeqEncoder, TransformerSeq2SeqEncoder, LSTMSeq2SeqEncoder
label_desc: Use image node_id 2 for calling the LSTMSeq2SeqModel obj's underlying member method code with example usage: obj.build_model(cls, src_embed, tgt_embed, num_layers, hidden_size, dropout, bidirectional, attention, bind_encoder_decoder_embed, bind_decoder_input_output_embed) and returns: cls