class_docstr: model
class_docstr_tok: ["model"]
code: def __init__(
      self,
      src_vocab_size,
      trg_vocab_size,
      max_length=256,
      n_layer=6,
      n_head=8,
      d_model=512,
      d_inner_hid=2048,
      dropout=0.1,
      weight_sharing=False,
      bos_id=0,
      eos_id=1,
      waitk=-1,
  ):
      super(SimultaneousTransformer, self).__init__()
      self.trg_vocab_size = trg_vocab_size
      self.emb_dim = d_model
      self.bos_id = bos_id
      self.eos_id = eos_id
      self.dropout = dropout
      self.waitk = waitk
      self.n_layer = n_layer
      self.n_head = n_head
      self.d_model = d_model
  
      self.src_word_embedding = WordEmbedding(
          vocab_size=src_vocab_size, emb_dim=d_model, bos_id=self.bos_id
      )
      self.src_pos_embedding = PositionalEmbedding(
          emb_dim=d_model, max_length=max_length + 1
      )
      if weight_sharing:
          assert (
              src_vocab_size == trg_vocab_size
          ), "Vocabularies in source and target should be same for weight sharing."
          self.trg_word_embedding = self.src_word_embedding
          self.trg_pos_embedding = self.src_pos_embedding
      else:
          self.trg_word_embedding = WordEmbedding(
              vocab_size=trg_vocab_size,
              emb_dim=d_model,
              bos_id=self.bos_id,
          )
          self.trg_pos_embedding = PositionalEmbedding(
              emb_dim=d_model, max_length=max_length + 1
          )
  
      encoder_layer = nn.TransformerEncoderLayer(
          d_model=d_model,
          nhead=n_head,
          dim_feedforward=d_inner_hid,
          dropout=dropout,
          activation="relu",
          normalize_before=True,
          bias_attr=[False, True],
      )
      encoder_norm = nn.LayerNorm(d_model)
      self.encoder = nn.TransformerEncoder(
          encoder_layer=encoder_layer,
          num_layers=n_layer,
          norm=encoder_norm,
      )
  
      decoder_layer = DecoderLayer(
          d_model=d_model,
          nhead=n_head,
          dim_feedforward=d_inner_hid,
          dropout=dropout,
          activation="relu",
          normalize_before=True,
          bias_attr=[False, False, True],
      )
      decoder_norm = nn.LayerNorm(d_model)
      self.decoder = Decoder(
          decoder_layer=decoder_layer,
          num_layers=n_layer,
          norm=decoder_norm,
      )
  
      if weight_sharing:
          self.linear = lambda x: paddle.matmul(
              x=x,
              y=self.trg_word_embedding.word_embedding.weight,
              transpose_y=True,
          )
      else:
          self.linear = nn.Linear(
              in_features=d_model,
              out_features=trg_vocab_size,
              bias_attr=False,
          )
  
file_path: PaddleHub/modules/text/simultaneous_translation/stacl/transformer_nist_wait_1/model.py
imports: import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddlenlp.transformers import WordEmbedding, PositionalEmbedding
label_desc: Use image node_id 1 to create a new SimultaneousTransformer object from inherited base classes: nn with example: obj = SimultaneousTransformer(src_vocab_size, trg_vocab_size, max_length, n_layer, n_head, d_model, d_inner_hid, dropout, weight_sharing, bos_id, eos_id, waitk)