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

Allow more subclassing of self-chat world #3955

Merged
merged 6 commits into from
Sep 8, 2021
Merged
Changes from 4 commits
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
31 changes: 23 additions & 8 deletions parlai/tasks/self_chat/worlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,7 @@ def make_agent_action(utterance: str, agent: Agent) -> Dict[str, Any]:

def parley(self):
if self.episode_done():
self.turn_cnt = 0
self.episode_cnt += 1
self.contexts = None
self.seed_utterances = None
agents = self.get_agents()
for a in agents:
a.reset()
self._end_episode()

if self.turn_cnt == 0:
self.acts = [None, None]
Expand All @@ -160,7 +154,7 @@ def parley(self):
self.agents[i].observe(validate(context))
# clear contexts so they are only added once per episode
self.contexts = None
elif self.seed_utterances:
elif self.seed_utterances and self._use_seed_utterances():
Copy link
Contributor

@spencerp spencerp Aug 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a slight preference toward integrating this logic closer with the above:

self.seed_utterances = self._get_seed_utt_acts(
    self.episode_cnt, self.agents
)

Maybe by putting the self._use_seed_utterances check inside of self._get_seed_utt_acts so there's a single source of truth (if self.seed_utterances)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point - changed

# pop the next two seed messages (there may be less or more than 2 total)
utts = self.seed_utterances[:2]
self.seed_utterances = self.seed_utterances[2:]
Expand All @@ -186,3 +180,24 @@ def parley(self):

self.update_counters()
self.turn_cnt += 1

def _end_episode(self):
"""
Apply logic to end the episode.
"""
self.turn_cnt = 0
self.episode_cnt += 1
self.contexts = None
self.seed_utterances = None
agents = self.get_agents()
for a in agents:
a.reset()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should wrap this into self.reset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a World.reset_agents() method - is this what you were thinking? We can't call World.reset() directly here, because there's additional logic there - i.e. World.reset() also resets self.total_parleys, self.total_exs, self.time, etc.


def _use_seed_utterances(self) -> bool:
"""
Logic to determine whether we should employ seed utterances.

Defaults to always using seed utterances if they exist, but this can be
overridden.
"""
return True