为什么在Transformer张量流中转换seq [:, tf.newaxis,tf.newaxis,:]

问题描述

嗨,我正在制作《变形金刚》聊天机器人。我在tf https://www.tensorflow.org/tutorials/text/transformer?hl=enAnd中找到了一个实例。 但是,我不知道为什么要使用create_padding_mask()?以及为什么要增加额外的尺寸... 我知道(batch_size,max_seq,d_model)

def create_padding_mask(seq):
  seq = tf.cast(tf.math.equal(seq,0),tf.float32)

  # add extra dimensions to add the padding
  # to the attention logits.
  return seq[:,tf.newaxis,:]  # (batch_size,1,seq_len)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)