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

Friends teacher include speaker in context #4678

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 24 additions & 8 deletions parlai/tasks/friends/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
from collections import defaultdict
import jsonlines
from parlai.utils.data import DatatypeHelper

import random
import copy
import os

RANDOM_SEED = 123
random.seed(RANDOM_SEED)

START_TOKEN = '__START__'
SILENCE_TOKEN = '__SILENCE__'

Expand All @@ -32,7 +35,8 @@ def __init__(self, opt, shared=None):
opt['datafile'] = _path(opt, self.fold + '.jsonl')
self.characters = opt['characters'].split(',')
self.character = opt['character']
self.use_silence_token = opt['use_silence_token']
self.include_speaker_in_context = opt['include_speaker_in_context']
self.silence_token_dropout = opt['silence_token_dropout']
self.silence_token = opt['silence_token']
self.use_start_token = opt['use_start_token']
self.start_token = opt['start_token']
Expand Down Expand Up @@ -86,14 +90,20 @@ def setup_data(self, datafile):
self.character == 'All' and speaker in self.characters
) or speaker == self.character:
yield {
"text": prev_context,
"label": f'{speaker}: {text}',
"text": prev_context + f'\n{speaker}:'
if self.include_speaker_in_context
else prev_context,
"label": text
if self.include_speaker_in_context
else f'{speaker}: {text}',
"characters": characters_string,
}, isConversationDone
elif self.use_silence_token:
elif random.random() > self.silence_token_dropout:
yield {
"text": prev_context,
"label": f'{self.character}: {self.silence_token}',
"label": self.silence_token
if self.include_speaker_in_context
else f'{self.character}: {self.silence_token}',
"characters": characters_string,
}, isConversationDone

Expand Down Expand Up @@ -125,10 +135,16 @@ def add_cmdline_args(
help='A comma-separated list of characters to train on when `--character` == `All`',
)
agent.add_argument(
'--use-silence-token',
'--include-speaker-in-context',
type='bool',
default=True,
help='Use silence token to generate training example for sentences where the chosen speaker is not speaking. Defaults to True.',
help='Append speaker to the end of each context. Defaults to True.',
)
agent.add_argument(
'--silence-token-dropout',
type=float,
default=1,
help='Dropout probability for using silence token to generate training example for sentences where the chosen speaker is not speaking. When set to 0, all silence tokens will generate training examples. When set to 1, no silence tokens will generate training examples. Defaults to 1.',
)
agent.add_argument(
'--silence-token',
Expand Down
38 changes: 24 additions & 14 deletions parlai/tasks/friends/test/friends_all_characters_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@ acts:
- - characters: Joey Tribbiani,Rachel Green,Ross Geller
episode_done: false
eval_labels:
- 'Rachel Green: Ooy.'
- Ooy.
id: friends:all_characters
text: 'Ross Geller: Everyone? I would like to make a toast to Rachel and Joey.'
text: 'Ross Geller: Everyone? I would like to make a toast to Rachel and Joey.

Rachel Green:'
- - characters: Joey Tribbiani,Rachel Green,Ross Geller
episode_done: false
eval_labels:
- 'Ross Geller: And to love. Ah, love. L-O-V-E, love. L is for life. And what
is life without love?'
- And to love. Ah, love. L-O-V-E, love. L is for life. And what is life without
love?
id: friends:all_characters
text: 'Ross Geller: Everyone? I would like to make a toast to Rachel and Joey.

Rachel Green: Ooy.'
Rachel Green: Ooy.

Ross Geller:'
- - characters: Joey Tribbiani,Rachel Green,Ross Geller
episode_done: false
eval_labels:
- 'Rachel Green: Oh my god, are we supposed to answer?'
- Oh my god, are we supposed to answer?
id: friends:all_characters
text: 'Ross Geller: Everyone? I would like to make a toast to Rachel and Joey.

Rachel Green: Ooy.

Ross Geller: And to love. Ah, love. L-O-V-E, love. L is for life. And what is
life without love?'
life without love?

Rachel Green:'
- - characters: Joey Tribbiani,Rachel Green,Ross Geller
episode_done: false
eval_labels:
- 'Ross Geller: O is for "oh, wow!" The V is for this very surprising turn of
events, which I''m still fine with by the way. E is for how extremely normal
I find it. That you two are together. And now one day you might get married
and have children of your own.'
- O is for "oh, wow!" The V is for this very surprising turn of events, which
I'm still fine with by the way. E is for how extremely normal I find it. That
you two are together. And now one day you might get married and have children
of your own.
id: friends:all_characters
text: 'Ross Geller: Everyone? I would like to make a toast to Rachel and Joey.

Expand All @@ -40,11 +46,13 @@ acts:
Ross Geller: And to love. Ah, love. L-O-V-E, love. L is for life. And what is
life without love?

Rachel Green: Oh my god, are we supposed to answer?'
Rachel Green: Oh my god, are we supposed to answer?

Ross Geller:'
- - characters: Joey Tribbiani,Rachel Green,Ross Geller
episode_done: false
eval_labels:
- 'Joey Tribbiani: Dude, are you okay?'
- Dude, are you okay?
id: friends:all_characters
text: 'Ross Geller: Everyone? I would like to make a toast to Rachel and Joey.

Expand All @@ -58,6 +66,8 @@ acts:
Ross Geller: O is for "oh, wow!" The V is for this very surprising turn of events,
which I''m still fine with by the way. E is for how extremely normal I find
it. That you two are together. And now one day you might get married and have
children of your own.'
children of your own.

Joey Tribbiani:'
num_episodes: 302
num_examples: 5774
34 changes: 22 additions & 12 deletions parlai/tasks/friends/test/friends_all_characters_train.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,40 @@ acts:
episode_done: false
id: friends:all_characters
labels:
- 'Ross Geller: Hi!'
text: 'Phoebe Buffay: Oh hey! Wait up!'
- Hi!
text: 'Phoebe Buffay: Oh hey! Wait up!

Ross Geller:'
- - characters: Phoebe Buffay,Ross Geller
episode_done: false
id: friends:all_characters
labels:
- 'Phoebe Buffay: Congratulations! I didn''t want to say anything in front of
Joey ''cause I didn''t know if he knew yet.'
- Congratulations! I didn't want to say anything in front of Joey 'cause I didn't
know if he knew yet.
text: 'Phoebe Buffay: Oh hey! Wait up!

Ross Geller: Hi!'
Ross Geller: Hi!

Phoebe Buffay:'
- - characters: Phoebe Buffay,Ross Geller
episode_done: false
id: friends:all_characters
labels:
- 'Ross Geller: What, that we had a baby? Come on let''s give him a little credit,
although, he did eat a piece of plastic fruit earlier.'
- What, that we had a baby? Come on let's give him a little credit, although,
he did eat a piece of plastic fruit earlier.
text: 'Phoebe Buffay: Oh hey! Wait up!

Ross Geller: Hi!

Phoebe Buffay: Congratulations! I didn''t want to say anything in front of Joey
''cause I didn''t know if he knew yet.'
''cause I didn''t know if he knew yet.

Ross Geller:'
- - characters: Phoebe Buffay,Ross Geller
episode_done: false
id: friends:all_characters
labels:
- 'Phoebe Buffay: No! No, that you and Rachel are engaged!'
- No! No, that you and Rachel are engaged!
text: 'Phoebe Buffay: Oh hey! Wait up!

Ross Geller: Hi!
Expand All @@ -39,12 +45,14 @@ acts:
''cause I didn''t know if he knew yet.

Ross Geller: What, that we had a baby? Come on let''s give him a little credit,
although, he did eat a piece of plastic fruit earlier.'
although, he did eat a piece of plastic fruit earlier.

Phoebe Buffay:'
- - characters: Phoebe Buffay,Ross Geller
episode_done: false
id: friends:all_characters
labels:
- 'Ross Geller: What?'
- What?
text: 'Phoebe Buffay: Oh hey! Wait up!

Ross Geller: Hi!
Expand All @@ -55,6 +63,8 @@ acts:
Ross Geller: What, that we had a baby? Come on let''s give him a little credit,
although, he did eat a piece of plastic fruit earlier.

Phoebe Buffay: No! No, that you and Rachel are engaged!'
Phoebe Buffay: No! No, that you and Rachel are engaged!

Ross Geller:'
num_episodes: 2427
num_examples: 46610
33 changes: 21 additions & 12 deletions parlai/tasks/friends/test/friends_all_characters_valid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@ acts:
Geller
episode_done: false
eval_labels:
- 'Joey Tribbiani: Chandler, if it really hurts that bad you should just tell
her.'
- Chandler, if it really hurts that bad you should just tell her.
id: friends:all_characters
text: 'Chandler Bing: I''m telling you, she gives the worst massages ever!! Okay,
it was like she was torturing me for information. And I wanted to give it up
I just-I didn''t know what it was!'
I just-I didn''t know what it was!

Joey Tribbiani:'
- - characters: Chandler Bing,Joey Tribbiani,Monica Geller,Phoebe Buffay,Rachel Green,Ross
Geller
episode_done: false
eval_labels:
- 'Chandler Bing: Look, for the first time in my life I''m in a real relationship.
Okay, I''m not gonna screw that up by y''know, telling the truth.'
- Look, for the first time in my life I'm in a real relationship. Okay, I'm not
gonna screw that up by y'know, telling the truth.
id: friends:all_characters
text: 'Chandler Bing: I''m telling you, she gives the worst massages ever!! Okay,
it was like she was torturing me for information. And I wanted to give it up
I just-I didn''t know what it was!

Joey Tribbiani: Chandler, if it really hurts that bad you should just tell her.'
Joey Tribbiani: Chandler, if it really hurts that bad you should just tell her.

Chandler Bing:'
- - characters: Chandler Bing,Joey Tribbiani,Monica Geller,Phoebe Buffay,Rachel Green,Ross
Geller
episode_done: false
eval_labels:
- 'Ross Geller: Hey.'
- Hey.
id: friends:all_characters
text: 'Chandler Bing: I''m telling you, she gives the worst massages ever!! Okay,
it was like she was torturing me for information. And I wanted to give it up
Expand All @@ -34,12 +37,14 @@ acts:
Joey Tribbiani: Chandler, if it really hurts that bad you should just tell her.

Chandler Bing: Look, for the first time in my life I''m in a real relationship.
Okay, I''m not gonna screw that up by y''know, telling the truth.'
Okay, I''m not gonna screw that up by y''know, telling the truth.

Ross Geller:'
- - characters: Chandler Bing,Joey Tribbiani,Monica Geller,Phoebe Buffay,Rachel Green,Ross
Geller
episode_done: false
eval_labels:
- 'Joey Tribbiani: Whoa, dude, look out! You almost crushed my hat!'
- Whoa, dude, look out! You almost crushed my hat!
id: friends:all_characters
text: 'Chandler Bing: I''m telling you, she gives the worst massages ever!! Okay,
it was like she was torturing me for information. And I wanted to give it up
Expand All @@ -50,12 +55,14 @@ acts:
Chandler Bing: Look, for the first time in my life I''m in a real relationship.
Okay, I''m not gonna screw that up by y''know, telling the truth.

Ross Geller: Hey.'
Ross Geller: Hey.

Joey Tribbiani:'
- - characters: Chandler Bing,Joey Tribbiani,Monica Geller,Phoebe Buffay,Rachel Green,Ross
Geller
episode_done: false
eval_labels:
- 'Ross Geller: Sorry.'
- Sorry.
id: friends:all_characters
text: 'Chandler Bing: I''m telling you, she gives the worst massages ever!! Okay,
it was like she was torturing me for information. And I wanted to give it up
Expand All @@ -68,6 +75,8 @@ acts:

Ross Geller: Hey.

Joey Tribbiani: Whoa, dude, look out! You almost crushed my hat!'
Joey Tribbiani: Whoa, dude, look out! You almost crushed my hat!

Ross Geller:'
num_episodes: 308
num_examples: 5855
Loading