code: def gen_bias(encoder_inputs, decoder_inputs, step):
      decoder_bsz, decoder_seqlen = decoder_inputs.shape[:2]
      attn_bias = L.reshape(
          L.range(0, decoder_seqlen, 1, dtype="float32") + 1, [1, -1, 1]
      )
      decoder_bias = L.cast(
          (
              L.matmul(attn_bias, 1.0 / attn_bias, transpose_y=True)
              >= 1.0
          ),
          "float32",
      )  # [1, 1, decoderlen, decoderlen]
      encoder_bias = L.unsqueeze(
          L.cast(L.ones_like(encoder_inputs), "float32"), [1]
      )  # [bsz, 1, encoderlen]
      encoder_bias = L.expand(
          encoder_bias, [1, decoder_seqlen, 1]
      )  # [bsz,decoderlen, encoderlen]
      decoder_bias = L.expand(
          decoder_bias, [decoder_bsz, 1, 1]
      )  # [bsz, decoderlen, decoderlen]
      if step > 0:
          bias = L.concat(
              [
                  encoder_bias,
                  L.ones(
                      [decoder_bsz, decoder_seqlen, step], "float32"
                  ),
                  decoder_bias,
              ],
              -1,
          )
      else:
          bias = L.concat([encoder_bias, decoder_bias], -1)
      return bias
  
file_path: PaddleHub/modules/text/text_generation/reading_pictures_writing_poems_for_midautumn/MidAutumnPoetry/model/decode.py
imports: import re
  import numpy
  from collections import namedtuple
  import paddle.fluid
  import paddle.fluid.layers
  import paddle.fluid.dygraph
label_desc: Use image node_id 1 for calling a global function with example usage: gen_bias(encoder_inputs, decoder_inputs, step) and returns: bias