This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
import random | ||
from typing import List | ||
from parlai.core.message import Message | ||
from parlai.core.mutators import register_mutator, ManyEpisodeMutator | ||
|
||
|
||
@register_mutator("ltm_mutator") | ||
class LongTermMemoryMutator(ManyEpisodeMutator): | ||
""" | ||
Replaces the episode labels in messages with "personal_knwowledge". | ||
Episodes are flattened to ensure dialogue history is maintained appropriately. | ||
""" | ||
|
||
def many_episode_mutation(self, episode: List[Message]) -> List[List[Message]]: | ||
history = [] | ||
for message in episode: | ||
if message['text'] == '__SILENCE__': | ||
continue | ||
history.append(message.pop('text')) | ||
message['text'] = '\n'.join(history) | ||
labels = message.pop('labels') | ||
message['labels'] = ["personal_knowledge"] | ||
yield [message] | ||
history.append(random.choice(labels)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters