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

Self chat from messages in file #3580

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions parlai/scripts/self_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def setup_args(parser=None):
default=False,
help='Automatically seed conversation with messages from task dataset.',
)
parser.add_argument(
'--seed-messages-from-file',
default=None,
help='If specified, loads newline-separated strings from the file as conversation starters.',
)
parser.add_argument(
'--outfile', type=str, default=None, help='File to save self chat logs'
)
Expand Down
9 changes: 9 additions & 0 deletions parlai/tasks/self_chat/worlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def load_openers(opt) -> Optional[List[str]]:
return list(openers)


def load_openers_from_file(filepath: str) -> List[str]:
openers = []
with open(filepath, 'r') as f:
openers = [l.strip() for l in f]
return openers


class SelfChatWorld(DialogPartnerWorld):
def __init__(self, opt, agents, shared=None):
super().__init__(opt, agents, shared)
Expand Down Expand Up @@ -81,6 +88,8 @@ def init_openers(self) -> None:
"""
if self.opt.get('seed_messages_from_task'):
self._openers = load_openers(self.opt)
elif self.opt.get('seed_messages_from_file'):
self._openers = load_openers_from_file(self.opt['seed_messages_from_file'])

def get_openers(self, episode_num: int) -> Optional[List[str]]:
"""
Expand Down