New DailyDialog Teacher to exclude __SILENCE__ tokens
@@ -33,7 +33,7 @@ START_ENTRY = {
}
-class DefaultTeacher(FixedDialogTeacher):
+class Convai2Teacher(FixedDialogTeacher):
def __init__(self, opt, shared=None):
super().__init__(opt, shared)
self.opt = opt
@@ -88,3 +88,45 @@ class DefaultTeacher(FixedDialogTeacher):
shared = super().share()
shared['data'] = self.data
return shared
+
+
+class NoStartTeacher(Convai2Teacher):
+ """
+ Same as default teacher, but it doesn't contain __SILENCE__ entries.
+ If we are the first speaker, then the first utterance is skipped.
+ """
+ def __init__(self, opt, shared=None):
+ super().__init__(opt, shared)
+
+ # Calculate the correct number of examples.
+ self.num_exs = sum(len(d['dialogue']) - 1 for d in self.data)
+
+ # Store all episodes separately, so we can deal with 2-turn dialogs.
+ self.all_eps = self.data + [d for d in self.data if len(d['dialogue']) > 2]
+ self.num_eps = len(self.all_eps)
+
+ def get(self, episode_idx, entry_idx=0):
+ full_eps = self.all_eps[episode_idx]
+ entries = full_eps['dialogue']
+
+ # Sometimes we're speaker 1 and sometimes we're speaker 2.
+ # We can't be speaker 1 if dialog has only 2 turns.
+ speaker_id = int(episode_idx >= len(self.data))
+
+ their_turn = entries[speaker_id + 2 * entry_idx]
+ my_turn = entries[1 + speaker_id + 2 * entry_idx]
+ episode_done = 2 * entry_idx + speaker_id + 1 >= len(entries) - 2
+
+ action = {
+ 'topic': full_eps['topic'],
+ 'text': their_turn['text'],
+ 'emotion': their_turn['emotion'],
+ 'act_type': their_turn['act'],
+ 'labels': [my_turn['text']],
+ 'episode_done': episode_done,
+ }
+ return action
+
+
+class DefaultTeacher(Convai2Teacher):
+ pass
