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

[SeeKeR] Support Selfchat #4634

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 15 additions & 4 deletions projects/seeker/agents/seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def add_cmdline_args(
default=False,
help='Whether to make model act output fully serializable.',
)
combo_fid.add_argument(
'--force-skip-retrieval',
type='bool',
default=False,
help='If True, we force skip retrieval on any/all incoming examples',
)

def build_model(self) -> ComboFidModel:
"""
Expand All @@ -107,9 +113,12 @@ def batchify(self, obs_batch: List[Message], sort: bool = False) -> Batch:
batch = super().batchify(obs_batch, sort)
valid_exs = [ex for ex in obs_batch if self.is_valid(ex)]
if valid_exs:
skip_retrieval = [
ex.get(self.opt['skip_retrieval_key'], False) for ex in valid_exs
]
if self.opt.get('force_skip_retrieval', False):
skip_retrieval = [True] * len(valid_exs)
else:
skip_retrieval = [
ex.get(self.opt['skip_retrieval_key'], False) for ex in valid_exs
]
batch.skip_retrieval_vec = torch.BoolTensor(skip_retrieval)
if any(ex.get('prior_knowledge_responses') for ex in valid_exs):
vecs, _lens = self._pad_tensor(
Expand Down Expand Up @@ -563,7 +572,9 @@ def observe(self, observation: Message) -> Dict[str, Message]:
for key in ['label_candidates', 'knowledge']:
# Delete unnecessarily large keys
observation.pop(key, '')
observation['knowledge_response'] = observation.get('checked_sentence', '')
observation.force_set(
'knowledge_response', observation.get('checked_sentence', '')
)

raw_observation = copy.deepcopy(observation)
# This part is *specifically* for document chunking.
Expand Down
13 changes: 13 additions & 0 deletions tests/nightly/gpu/test_seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import unittest

import parlai.scripts.eval_model as ems
from parlai.scripts.self_chat import SelfChat
import parlai.utils.testing as testing_utils

R2C2_BASE_400M = 'zoo:seeker/r2c2_base_400M/model'
Expand Down Expand Up @@ -111,3 +112,15 @@ def test_blenderbot(self):
'datatype': 'valid',
}
ems.EvalModel.main(**opt)


class TestSeekerSelfChat(unittest.TestCase):
def test_400m(self):
SelfChat.main(
model_file='zoo:seeker/seeker_dialogue_400M/model',
num_self_chats=1,
init_opt='gen/seeker_dialogue',
search_decision='never',
search_server='none',
force_skip_retrieval=True,
)