class_docstr: model
class_docstr_tok: ["model"]
code: def forward(self, src_word, trg_word):
      src_max_len = paddle.shape(src_word)[-1]
      trg_max_len = paddle.shape(trg_word)[-1]
      base_attn_bias = (
          paddle.cast(
              src_word == self.bos_id, dtype=paddle.get_default_dtype()
          ).unsqueeze([1, 2])
          * -1e9
      )
      src_slf_attn_bias = base_attn_bias
      src_slf_attn_bias.stop_gradient = True
      trg_slf_attn_bias = paddle.tensor.triu(
          (
              paddle.ones(
                  (trg_max_len, trg_max_len),
                  dtype=paddle.get_default_dtype(),
              )
              * -np.inf
          ),
          1,
      )
      trg_slf_attn_bias.stop_gradient = True
      trg_src_attn_bias = paddle.tile(
          base_attn_bias, [1, 1, trg_max_len, 1]
      )
      src_pos = paddle.cast(
          src_word != self.bos_id, dtype="int64"
      ) * paddle.arange(start=0, end=src_max_len)
      trg_pos = paddle.cast(
          trg_word != self.bos_id, dtype="int64"
      ) * paddle.arange(start=0, end=trg_max_len)
      src_emb = self.src_word_embedding(src_word)
      src_pos_emb = self.src_pos_embedding(src_pos)
      src_emb = src_emb + src_pos_emb
      enc_input = (
          F.dropout(src_emb, p=self.dropout, training=self.training)
          if self.dropout
          else src_emb
      )
      with paddle.static.amp.fp16_guard():
          if self.waitk >= src_max_len or self.waitk == -1:
              # Full sentence
              enc_outputs = [
                  self.encoder(enc_input, src_mask=src_slf_attn_bias)
              ]
          else:
              # Wait-k policy
              enc_outputs = []
              for i in range(self.waitk, src_max_len + 1):
                  enc_output = self.encoder(
                      enc_input[:, :i, :],
                      src_mask=src_slf_attn_bias[:, :, :, :i],
                  )
                  enc_outputs.append(enc_output)
  
          trg_emb = self.trg_word_embedding(trg_word)
          trg_pos_emb = self.trg_pos_embedding(trg_pos)
          trg_emb = trg_emb + trg_pos_emb
          dec_input = (
              F.dropout(trg_emb, p=self.dropout, training=self.training)
              if self.dropout
              else trg_emb
          )
          dec_output = self.decoder(
              dec_input,
              enc_outputs,
              tgt_mask=trg_slf_attn_bias,
              memory_mask=trg_src_attn_bias,
          )
  
          predict = self.linear(dec_output)
  
      return predict
  
file_path: PaddleHub/modules/text/simultaneous_translation/stacl/transformer_nist_wait_3/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 2 for calling the SimultaneousTransformer obj's underlying member method code with example usage: obj.forward(src_word, trg_word) and returns: predict