(beam_width, parent_ids, sequence_lengths, outputs, end_id, max_seq_len=None)
| 74 | return memory, memory_sequence_length |
| 75 | |
| 76 | def finalize(beam_width, parent_ids, sequence_lengths, outputs, end_id, max_seq_len=None): |
| 77 | maximum_lengths = tf.reduce_max(tf.reshape( |
| 78 | sequence_lengths, [-1, beam_width]), axis=-1) |
| 79 | |
| 80 | if max_seq_len != None: |
| 81 | array_shape = [max_seq_len, -1, beam_width] |
| 82 | else: |
| 83 | array_shape = [tf.reduce_max(maximum_lengths), -1, beam_width] |
| 84 | |
| 85 | step_ids = tf.reshape(outputs, array_shape) |
| 86 | parent_ids = tf.reshape(parent_ids, array_shape) |
| 87 | |
| 88 | ids = tf.contrib.seq2seq.gather_tree( |
| 89 | step_ids, parent_ids, maximum_lengths, end_id) |
| 90 | |
| 91 | ids = tf.transpose(ids, perm=[1, 2, 0]) |
| 92 | lengths = tf.not_equal(ids, end_id) |
| 93 | lengths = tf.cast(lengths, tf.int32) |
| 94 | lengths = tf.reduce_sum(lengths, axis=-1) |
| 95 | return ids, lengths |
| 96 | |
| 97 | def decoding_body(word_ids, |
| 98 | step, |
no outgoing calls
no test coverage detected