(facts, ATTENTION_SIZE, mask, stag='null')
| 369 | return output |
| 370 | |
| 371 | def self_attention(facts, ATTENTION_SIZE, mask, stag='null'): |
| 372 | if len(facts.get_shape().as_list()) == 2: |
| 373 | facts = tf.expand_dims(facts, 1) |
| 374 | |
| 375 | def cond(batch, output, i): |
| 376 | return tf.less(i, tf.shape(batch)[1]) |
| 377 | |
| 378 | def body(batch, output, i): |
| 379 | self_attention_tmp = din_fcn_attention(batch[:, i, :], batch[:, 0:i+1, :], |
| 380 | ATTENTION_SIZE, mask[:, 0:i+1], softmax_stag=1, stag=stag, |
| 381 | mode='LIST') |
| 382 | self_attention_tmp = tf.reduce_sum(self_attention_tmp, 1) |
| 383 | output = output.write(i, self_attention_tmp) |
| 384 | return batch, output, i + 1 |
| 385 | |
| 386 | output_ta = tf.TensorArray(dtype=tf.float32, |
| 387 | size=0, |
| 388 | dynamic_size=True, |
| 389 | element_shape=(facts[:, 0, :].get_shape())) |
| 390 | _, output_op, _ = tf.while_loop(cond, body, [facts, output_ta, 0]) |
| 391 | self_attention = output_op.stack() |
| 392 | self_attention = tf.transpose(self_attention, perm = [1, 0, 2]) |
| 393 | return self_attention |
| 394 | |
| 395 | def self_all_attention(facts, ATTENTION_SIZE, mask, stag='null'): |
| 396 | if len(facts.get_shape().as_list()) == 2: |
nothing calls this directly
no outgoing calls
no test coverage detected