'Adds a sequence of beam parsing steps.'

def _BuildSequence(self, batch_size, max_steps, features, state, use_average=False):

    def Advance(state, step, scores_array, alive, alive_steps, *features):
        scores = self._BuildNetwork(features, return_average=use_average)['logits']
        scores_array = scores_array.write(step, scores)
        (features, state, alive) = gen_parser_ops.beam_parser(state, scores, self._feature_size)
        return ([state, (step + 1), scores_array, alive, (alive_steps + tf.cast(alive, tf.int32))] + list(features))
    def KeepGoing(*args):
        return tf.logical_and((args[1] < max_steps), tf.reduce_any(args[3]))
    step = tf.constant(0, tf.int32, [])
    scores_array = tensor_array_ops.TensorArray(dtype=tf.float32, size=0, dynamic_size=True)
    alive = tf.constant(True, tf.bool, [batch_size])
    alive_steps = tf.constant(0, tf.int32, [batch_size])
    t = tf.while_loop(KeepGoing, Advance, ([state, step, scores_array, alive, alive_steps] + list(features)), shape_invariants=([tf.TensorShape(None)] * (len(features) + 5)), parallel_iterations=100)
    return {'state': t[0], 'concat_scores': t[2].concat(), 'alive': t[3], 'alive_steps': t[4]}
