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
[BlenderBot2] clean up reply during interactive mode #4379
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
The Memory Decoder examines the context and generates memories to write to | ||
the long-term memory module. | ||
""" | ||
import re | ||
import copy | ||
import torch | ||
import torch.nn | ||
|
@@ -253,6 +254,12 @@ def add_cmdline_args( | |
help='filter input to the global knowledge retriever such that any utterance containing ' | ||
'the phrase will not be given as input.', | ||
) | ||
bb2_group.add_argument( | ||
'--clean-reply', | ||
type=bool, | ||
default=False, | ||
help='filter reply during self_observe', | ||
) | ||
q_gen_group = parser.add_argument_group('BlenderBot2 Query Generator Args') | ||
q_gen_group.add_argument( | ||
'--query-generator-ignore-phrase', | ||
|
@@ -898,6 +905,39 @@ def compute_loss( | |
else: | ||
return loss | ||
|
||
def _clean_text(self, txt): | ||
cleaned_txt = re.sub(r'_[\S]*unsafe_*', '', txt, flags=re.IGNORECASE) | ||
return cleaned_txt.strip() | ||
|
||
def self_observe(self, self_message: Message) -> None: | ||
""" | ||
Observe one's own utterance. | ||
Override TorchAgent.self_observe with the optional cleaned text | ||
|
||
:param self_message: | ||
The message corresponding to the output from batch_act. | ||
""" | ||
|
||
if ( | ||
self.opt('clean_reply', False) | ||
or self.observation['episode_done'] # last example in the episode | ||
or use_reply == 'none' # not including our own responses anyway | ||
jxmsML marked this conversation as resolved.
Show resolved
Hide resolved
|
||
or ( | ||
use_reply == 'label' | ||
and any([x in self.observation for l in ['labels', 'eval_labels']]) | ||
) # has true label | ||
): | ||
return super().self_observe(self_message) | ||
|
||
# otherwise, we use the CLEANED last output the model generated | ||
if self_message is not None: | ||
last_reply = self_message['text'] | ||
clean_reply = self._clean_text(last_reply) | ||
self.history.add_reply(clean_reply) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps we should just override the History class and do this logic there? |
||
return | ||
|
||
raise RuntimeError("Unexpected case in self_observe.") | ||
|
||
|
||
class BlenderBot2FidAgent(FidAgent, BlenderBot2RagAgent): | ||
model: BlenderBot2FidModel | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it returns here and doesn't go to cleaning the text if
clean_reply
isTrue
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to ALWAYS clean the reply and I think it's the right thing to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to ALWAYS clean the reply and I think it's the right thing to do?