(beam_width, parent_ids, sequence_lengths, outputs, end_id, max_seq_len=None)
| 20 | from examples.tensorflow.decoder.utils.position import SinusoidalPositionEncoder |
| 21 | |
| 22 | def finalize(beam_width, parent_ids, sequence_lengths, outputs, end_id, max_seq_len=None): |
| 23 | maximum_lengths = tf.reduce_max(tf.reshape( |
| 24 | sequence_lengths, [-1, beam_width]), axis=-1) |
| 25 | |
| 26 | if max_seq_len != None: |
| 27 | array_shape = [max_seq_len, -1, beam_width] |
| 28 | else: |
| 29 | array_shape = [tf.reduce_max(maximum_lengths), -1, beam_width] |
| 30 | |
| 31 | step_ids = tf.reshape(outputs, array_shape) |
| 32 | parent_ids = tf.reshape(parent_ids, array_shape) |
| 33 | |
| 34 | ids = tf.contrib.seq2seq.gather_tree( |
| 35 | step_ids, parent_ids, maximum_lengths, end_id) |
| 36 | |
| 37 | ids = tf.transpose(ids, perm=[1, 2, 0]) |
| 38 | lengths = tf.not_equal(ids, end_id) |
| 39 | lengths = tf.cast(lengths, tf.int32) |
| 40 | lengths = tf.reduce_sum(lengths, axis=-1) |
| 41 | return ids, lengths |
| 42 | |
| 43 | def ft_decoding(memory_tensor, |
| 44 | memory_sequence_length, |
nothing calls this directly
no outgoing calls
no test coverage detected