def _distance_logits(self, x, keys):
init = get_keras_initialization(self.init)
key_w = tf.get_variable("key_w", shape=keys.shape.as_list()[-1], initializer=init, dtype=tf.float32)
key_logits = tf.tensordot(keys, key_w, axes=[[2], [0]]) # (batch, key_len)
x_w = tf.get_variable("x_w", shape=x.shape.as_list()[-1], initializer=init, dtype=tf.float32)
x_logits = tf.tensordot(x, x_w, axes=[[2], [0]]) # (batch, x_len)
# Broadcasting will expand the arrays to (batch, x_len, key_len)
return tf.expand_dims(x_logits, axis=2) + tf.expand_dims(key_logits, axis=1)
评论列表
文章目录