需要把填充的部分标记为0,其余部分标记为1,才不会导致填充的部分被误认为是输入
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, tf.newaxis, :] # (batch_size, 1, 1, seq_len)
x = tf.constant([[7, 6, 0, 0, 1], [1, 2, 3, 0, 0], [0, 0, 0, 4, 5]])
create_padding_mask(x)
<tf.Tensor: shape=(3, 1, 1, 5), dtype=float32, numpy=
array([[[[0., 0., 1., 1., 0.]]],
[[[0., 0., 0., 1., 1.]]],
[[[1., 1., 1., 0., 0.]]]], dtype=float32)>
def create_look_ahead_mask(size):
mask = 1 - tf.linalg.band_part(tf.ones((size, size)), -1, 0)
return mask # (seq_len, seq_len)
x = tf.random.uniform((1, 3))
temp = create_look_ahead_mask(x.shape[1])
temp
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[0., 1., 1.],
[0., 0., 1.],
[0., 0., 0.]], dtype=float32)>
前言 前面的章节可以建议使用线上IDE进行练习与熟悉。 线上 Go IDE的网址在下方 https:...
在写React的时候其实有分为两种写法 Class Component this.state or ...
前言 前面我们先介绍了Pod, 控管Pod的ReplicaSet与管理ReplicaSet的Depl...
虚拟主机是什麽 虚拟主机(Virtual Hosting)又被称作共享主机(Shared Web H...
前一天我们学会了对资料进行简单的map处理之後,今天来聊一下排序 不论是进行人工的检视或是後续分析的...