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

wizint+wow: more knowledge pred changes #3999

Merged
merged 1 commit into from
Sep 9, 2021
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
2 changes: 1 addition & 1 deletion parlai/tasks/wizard_of_internet/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def message_mutation(self, message: Message) -> Message:
label1 = ' '.join(ls[0:ind])
label2 = ' '.join(ls[ind : len(ls)])

text += f'{label1}\n__label__ {label2} __endlabel__'
text += f'\n{label1}\n__label__ {label2} __endlabel__'
message['text'] = text

message['labels'] = [checked_sentence]
Expand Down
36 changes: 33 additions & 3 deletions parlai/tasks/wizard_of_wikipedia/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,9 +1303,8 @@ def message_mutation(self, message: Message) -> Message:
@register_mutator("checked_sentence_as_label")
class CheckedSentenceAsLabel(MessageMutator):
"""
Adds the dialogue sentence.

But only a single time. The label then becomes the checked sentence.
Adds the dialogue sentence to the end of the text. But only a single time.
The label then becomes the checked sentence.
"""

def message_mutation(self, message: Message) -> Message:
Expand All @@ -1322,3 +1321,34 @@ def message_mutation(self, message: Message) -> Message:
message['labels'] = [checked_sentence]

return message


@register_mutator("checked_sentence_as_label_lm")
class CheckedSentenceAsLabelLm(MessageMutator):
"""
Sets the checked sentences as the label, and the label to the end of text. Language
modeling version where a random piece of the label is sampled in the input.

E.g. run with: parlai display_data -t wizard_of_wikipedia -n 100 -dt valid --mutators
flatten,checked_sentence_as_label_lm --add-missing-turns all
"""

def message_mutation(self, message: Message) -> Message:
original_message = message.copy()
if 'text' not in message or 'labels' not in message or not message['labels']:
return original_message
text = message.pop('text')
labels = message.pop('labels')
dialogue_response = labels[0]
checked_sentence = message.get('checked_sentence', '')

ls = dialogue_response.split(' ')
ind = random.randint(0, len(ls) - 1)
label1 = ' '.join(ls[0:ind])
label2 = ' '.join(ls[ind : len(ls)])

text += f'\n{label1}\n{TOKEN_LABEL} {label2} {TOKEN_END_LABEL}'
message['text'] = text
message['labels'] = [checked_sentence]

return message