parlai/core/utils.py
def maintain_dialog_history(history, observation, reply='',
                            historyLength=1, useReplies="labels",
                            dict=None, useStartEndIndices=True):
    """Keeps track of dialog history, up to a truncation length.
    Either includes replies from the labels, model, or not all using param 'replies'."""

    def parse(txt):
        if dict is not None:
            vec =  dict.txt2vec(txt)
            if useStartEndIndices:
                parsed_x = deque([dict[dict.start_token]])
                parsed_x.extend(vec)
                parsed_x.append(dict[dict.end_token])
                return parsed_x
            else:
                return vec
        else:
            return [txt]

    if 'dialog' not in history:
        history['dialog'] = deque(maxlen=historyLength)
        history['episode_done'] = False
        history['labels'] = []

    if history['episode_done']:
        history['dialog'].clear()
        history['labels'] = []
        history['episode_done'] = False
 
    if useReplies != 'none':
        if useReplies == 'model':
            if reply != '':
                history['dialog'].extend(parse(reply))
        elif len(history['labels']) > 0:
            r = history['labels'][0]
            history['dialog'].extend(parse(r))
    if 'text' in observation:
        history['dialog'].extend(parse(observation['text']))

    history['episode_done'] = observation['episode_done']
    if 'labels' in observation:
        history['labels'] = observation['labels']
    elif 'eval_labels' in observation:
        history['labels'] = observation['eval_labels']
    return history['dialog']
Keeps track of dialog history, up to a truncation length.
    Either includes replies from the labels, model, or not all using param 'replies'.
Keeps track of dialog history, up to a truncation length.
Either includes replies from the labels, model, or not all using param 'replies'.
Keeps track of dialog history up to a truncation length . Either includes replies from the labels model or not all using param ' replies ' .
def maintain_dialog_history(history, observation, reply='',
                            historyLength=1, useReplies="labels",
                            dict=None, useStartEndIndices=True):
    def parse(txt):
        if dict is not None:
            vec =  dict.txt2vec(txt)
            if useStartEndIndices:
                parsed_x = deque([dict[dict.start_token]])
                parsed_x.extend(vec)
                parsed_x.append(dict[dict.end_token])
                return parsed_x
            else:
                return vec
        else:
            return [txt]
    if 'dialog' not in history:
        history['dialog'] = deque(maxlen=historyLength)
        history['episode_done'] = False
        history['labels'] = []
    if history['episode_done']:
        history['dialog'].clear()
        history['labels'] = []
        history['episode_done'] = False
    if useReplies != 'none':
        if useReplies == 'model':
            if reply != '':
                history['dialog'].extend(parse(reply))
        elif len(history['labels']) > 0:
            r = history['labels'][0]
            history['dialog'].extend(parse(r))
    if 'text' in observation:
        history['dialog'].extend(parse(observation['text']))
    history['episode_done'] = observation['episode_done']
    if 'labels' in observation:
        history['labels'] = observation['labels']
    elif 'eval_labels' in observation:
        history['labels'] = observation['eval_labels']
    return history['dialog']
def maintain_dialog_history ( history , observation , reply = '' , historyLength = 1 , useReplies = "labels" , dict = None , useStartEndIndices = True ) : def parse ( txt ) : if dict is not None : vec = dict . txt2vec ( txt ) if useStartEndIndices : parsed_x = deque ( [ dict [ dict . start_token ] ] ) parsed_x . extend ( vec ) parsed_x . append ( dict [ dict . end_token ] ) return parsed_x else : return vec else : return [ txt ] if 'dialog' not in history : history [ 'dialog' ] = deque ( maxlen = historyLength ) history [ 'episode_done' ] = False history [ 'labels' ] = [ ] if history [ 'episode_done' ] : history [ 'dialog' ] . clear ( ) history [ 'labels' ] = [ ] history [ 'episode_done' ] = False if useReplies != 'none' : if useReplies == 'model' : if reply != '' : history [ 'dialog' ] . extend ( parse ( reply ) ) elif len ( history [ 'labels' ] ) > 0 : r = history [ 'labels' ] [ 0 ] history [ 'dialog' ] . extend ( parse ( r ) ) if 'text' in observation : history [ 'dialog' ] . extend ( parse ( observation [ 'text' ] ) ) history [ 'episode_done' ] = observation [ 'episode_done' ] if 'labels' in observation : history [ 'labels' ] = observation [ 'labels' ] elif 'eval_labels' in observation : history [ 'labels' ] = observation [ 'eval_labels' ] return history [ 'dialog' ]
Keeps track of dialog history, up to a truncation length.
Keeps track of dialog history up to a truncation length .
"""Keeps track of dialog history, up to a truncation length.
    Either includes replies from the labels, model, or not all using param 'replies'."""
history
observation
reply
historyLength
useReplies
dict
useStartEndIndices