(self, v, k, q, mask)
return output, attention_weights
call function
call function
call function
def call(self, v, k, q, mask):
    """ call function """
    batch_size = tf.shape(q)[0]

    q = self.wq(q)  # (batch_size, seq_len, hiddn_dim)
    k = self.wk(k)  # (batch_size, seq_len, hiddn_dim)
    v = self.wv(v)  # (batch_size, seq_len, hiddn_dim)

    q = self.split_heads(
        q, batch_size)  # (batch_size, num_heads, seq_len_q, depth)
    k = self.split_heads(
        k, batch_size)  # (batch_size, num_heads, seq_len_k, depth)
    v = self.split_heads(
        v, batch_size)  # (batch_size, num_heads, seq_len_v, depth)

    # scaled_attention.shape == (batch_size, num_heads, seq_len_q, depth)
    # attention_weights.shape == (batch_size, num_heads, seq_len_q, seq_len_k)
    scaled_attention, attention_weights = self.attention(q, k, v, mask)

    # (batch_size, seq_len_q, num_heads, depth)
    scaled_attention = tf.transpose(scaled_attention, perm=[0, 2, 1, 3])

    # (batch_size, seq_len_q, d_model)
    concat_attention = tf.reshape(scaled_attention,
                                  (batch_size, -1, self.d_model))

    output = self.dense(concat_attention)  # (batch_size, seq_len_q, d_model)

    return output, attention_weights
def call ( self , v , k , q , mask ) : batch_size = tf . shape ( q ) [ 0 ] q = self . wq ( q ) # (batch_size, seq_len, hiddn_dim) k = self . wk ( k ) # (batch_size, seq_len, hiddn_dim) v = self . wv ( v ) # (batch_size, seq_len, hiddn_dim) q = self . split_heads ( q , batch_size ) # (batch_size, num_heads, seq_len_q, depth) k = self . split_heads ( k , batch_size ) # (batch_size, num_heads, seq_len_k, depth) v = self . split_heads ( v , batch_size ) # (batch_size, num_heads, seq_len_v, depth) # scaled_attention.shape == (batch_size, num_heads, seq_len_q, depth) # attention_weights.shape == (batch_size, num_heads, seq_len_q, seq_len_k) scaled_attention , attention_weights = self . attention ( q , k , v , mask ) # (batch_size, seq_len_q, num_heads, depth) scaled_attention = tf . transpose ( scaled_attention , perm = [ 0 , 2 , 1 , 3 ] ) # (batch_size, seq_len_q, d_model) concat_attention = tf . reshape ( scaled_attention , ( batch_size , - 1 , self . d_model ) ) output = self . dense ( concat_attention ) # (batch_size, seq_len_q, d_model) return output , attention_weights