Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Preserve the order of loaded openers in selfchat (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker023 authored Aug 10, 2021
1 parent b414f39 commit d88cccc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions parlai/tasks/self_chat/worlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ def load_openers(opt) -> Optional[List[str]]:
task_world = create_task(task_opt, task_agent)

# run through task data, collecting all first messages
openers = set()
openers = []
is_first_turn = True
while not task_world.epoch_done():
task_world.parley()
msg = task_world.get_acts()[0]
# add only the first message in the episode
if is_first_turn and msg.get('text'):
openers.add(msg['text'])
openers.append(msg['text'])
is_first_turn = msg.get('episode_done', False)

# remove duplicates while preserving the ordering of the loaded openers
openers = list(dict.fromkeys(openers))

print(f'[ loaded {len(openers)} openers ]')
return list(openers)
return openers


def load_openers_from_file(filepath: str) -> List[str]:
Expand Down

0 comments on commit d88cccc

Please sign in to comment.