parlai/core/worlds.py
def display_messages(msgs):
    """Returns a string describing the set of messages provided"""
    lines = []
    episode_done = False
    for index, msg in enumerate(msgs):
        if msg is None:
            continue
        if msg.get('episode_done'):
            episode_done = True
        # Possibly indent the text (for the second speaker, if two).
        space = ''
        if len(msgs) == 2 and index == 1:
            space = '   '
        if msg.get('reward', None) is not None:
            lines.append(space + '[reward: {r}]'.format(r=msg['reward']))
        if type(msg.get('image')) == str:
            lines.append(msg['image'])
        if msg.get('text', ''):
            ID = '[' + msg['id'] + ']: ' if 'id' in msg else ''
            lines.append(space + ID + msg['text'])
        if msg.get('labels'):
            lines.append(space + ('[labels: {}]'.format(
                        '|'.join(msg['labels']))))
        if msg.get('eval_labels'):
            lines.append(space + ('[eval_labels: {}]'.format(
                        '|'.join(msg['eval_labels']))))
        if msg.get('label_candidates'):
            cand_len = len(msg['label_candidates'])
            if cand_len <= 10:
                lines.append(space + ('[cands: {}]'.format(
                        '|'.join(msg['label_candidates']))))
            else:
                # select five label_candidates from the candidate set,
                # can't slice in because it's a set
                cand_iter = iter(msg['label_candidates'])
                display_cands = (next(cand_iter) for _ in range(5))
                # print those cands plus how many cands remain
                lines.append(space + ('[cands: {}{}]'.format(
                        '|'.join(display_cands),
                        '| ...and {} more'.format(cand_len - 5)
                        )))
    if episode_done:
        lines.append('- - - - - - - - - - - - - - - - - - - - -')
    return '\n'.join(lines)
Returns a string describing the set of messages provided
Returns a string describing the set of messages provided
Returns a string describing the set of messages provided
def display_messages(msgs):
    lines = []
    episode_done = False
    for index, msg in enumerate(msgs):
        if msg is None:
            continue
        if msg.get('episode_done'):
            episode_done = True
        space = ''
        if len(msgs) == 2 and index == 1:
            space = '   '
        if msg.get('reward', None) is not None:
            lines.append(space + '[reward: {r}]'.format(r=msg['reward']))
        if type(msg.get('image')) == str:
            lines.append(msg['image'])
        if msg.get('text', ''):
            ID = '[' + msg['id'] + ']: ' if 'id' in msg else ''
            lines.append(space + ID + msg['text'])
        if msg.get('labels'):
            lines.append(space + ('[labels: {}]'.format(
                        '|'.join(msg['labels']))))
        if msg.get('eval_labels'):
            lines.append(space + ('[eval_labels: {}]'.format(
                        '|'.join(msg['eval_labels']))))
        if msg.get('label_candidates'):
            cand_len = len(msg['label_candidates'])
            if cand_len <= 10:
                lines.append(space + ('[cands: {}]'.format(
                        '|'.join(msg['label_candidates']))))
            else:
                cand_iter = iter(msg['label_candidates'])
                display_cands = (next(cand_iter) for _ in range(5))
                lines.append(space + ('[cands: {}{}]'.format(
                        '|'.join(display_cands),
                        '| ...and {} more'.format(cand_len - 5)
                        )))
    if episode_done:
        lines.append('- - - - - - - - - - - - - - - - - - - - -')
    return '\n'.join(lines)
def display_messages ( msgs ) : lines = [ ] episode_done = False for index , msg in enumerate ( msgs ) : if msg is None : continue if msg . get ( 'episode_done' ) : episode_done = True space = '' if len ( msgs ) == 2 and index == 1 : space = '   ' if msg . get ( 'reward' , None ) is not None : lines . append ( space + '[reward: {r}]' . format ( r = msg [ 'reward' ] ) ) if type ( msg . get ( 'image' ) ) == str : lines . append ( msg [ 'image' ] ) if msg . get ( 'text' , '' ) : ID = '[' + msg [ 'id' ] + ']: ' if 'id' in msg else '' lines . append ( space + ID + msg [ 'text' ] ) if msg . get ( 'labels' ) : lines . append ( space + ( '[labels: {}]' . format ( '|' . join ( msg [ 'labels' ] ) ) ) ) if msg . get ( 'eval_labels' ) : lines . append ( space + ( '[eval_labels: {}]' . format ( '|' . join ( msg [ 'eval_labels' ] ) ) ) ) if msg . get ( 'label_candidates' ) : cand_len = len ( msg [ 'label_candidates' ] ) if cand_len <= 10 : lines . append ( space + ( '[cands: {}]' . format ( '|' . join ( msg [ 'label_candidates' ] ) ) ) ) else : cand_iter = iter ( msg [ 'label_candidates' ] ) display_cands = ( next ( cand_iter ) for _ in range ( 5 ) ) lines . append ( space + ( '[cands: {}{}]' . format ( '|' . join ( display_cands ) , '| ...and {} more' . format ( cand_len - 5 ) ) ) ) if episode_done : lines . append ( '- - - - - - - - - - - - - - - - - - - - -' ) return '\n' . join ( lines )
Returns a string describing the set of messages provided
Returns a string describing the set of messages provided
"""Returns a string describing the set of messages provided""" # Possibly indent the text (for the second speaker, if two). # select five label_candidates from the candidate set, # can't slice in because it's a set # print those cands plus how many cands remain
msgs