def generation_done(beam_obj, training_info, end_token):
    """ Stop when end token is reached or the sentence is the maximal length. """
    return beam_obj.last_id == end_token or len(beam_obj.utterance) == training_info['max_length_targ']