MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / self_all_attention

Function self_all_attention

DIEN/utils.py:395–417  ·  view source on GitHub ↗
(facts, ATTENTION_SIZE, mask, stag='null')

Source from the content-addressed store, hash-verified

393 return self_attention
394
395def self_all_attention(facts, ATTENTION_SIZE, mask, stag='null'):
396 if len(facts.get_shape().as_list()) == 2:
397 facts = tf.expand_dims(facts, 1)
398
399 def cond(batch, output, i):
400 return tf.less(i, tf.shape(batch)[1])
401
402 def body(batch, output, i):
403 self_attention_tmp = din_fcn_attention(batch[:, i, :], batch,
404 ATTENTION_SIZE, mask, softmax_stag=1, stag=stag,
405 mode='LIST')
406 self_attention_tmp = tf.reduce_sum(self_attention_tmp, 1)
407 output = output.write(i, self_attention_tmp)
408 return batch, output, i + 1
409
410 output_ta = tf.TensorArray(dtype=tf.float32,
411 size=0,
412 dynamic_size=True,
413 element_shape=(facts[:, 0, :].get_shape()))
414 _, output_op, _ = tf.while_loop(cond, body, [facts, output_ta, 0])
415 self_attention = output_op.stack()
416 self_attention = tf.transpose(self_attention, perm = [1, 0, 2])
417 return self_attention
418
419def din_fcn_shine(query, facts, attention_size, mask, stag='null', mode='SUM', softmax_stag=1, time_major=False, return_alphas=False):
420 if isinstance(facts, tuple):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected