From d9d17f857ccb4c7820cfa947adbff97d0b845bad Mon Sep 17 00:00:00 2001 From: Steffen Cruz Date: Mon, 23 Oct 2023 17:59:18 -0600 Subject: [PATCH 1/3] Restrict the format of acceptable followup completions --- prompting/validators/forward.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prompting/validators/forward.py b/prompting/validators/forward.py index 9d95e66..d309666 100644 --- a/prompting/validators/forward.py +++ b/prompting/validators/forward.py @@ -97,6 +97,20 @@ async def run_step( synapse=synapse, timeout=timeout, ) + # Restrict the format of acceptable followup completions. + for response in responses: + # remove leading and trailing periods + completion = response.completion.strip('.') + if 'followup' in name and len(completion)>0: + if '?' in completion: + # take first question that is found and only use the sentence before the question mark + completion = completion.split('?')[0].split('.')[-1] + else: + # otherwise take the last sentence + completion = completion.split('.')[-1].split('.')[-1] + + response.completion = completion.strip() + '?' + # Compute the rewards for the responses given the prompt. rewards: torch.FloatTensor = torch.zeros(len(responses), dtype=torch.float32).to( From 5c3a60f3d1caf0f27defea23aa0e0995f8be1f28 Mon Sep 17 00:00:00 2001 From: Steffen Cruz Date: Tue, 24 Oct 2023 10:21:41 -0600 Subject: [PATCH 2/3] Limit quaestion to 40 words --- prompting/validators/forward.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prompting/validators/forward.py b/prompting/validators/forward.py index d309666..f79038d 100644 --- a/prompting/validators/forward.py +++ b/prompting/validators/forward.py @@ -97,11 +97,15 @@ async def run_step( synapse=synapse, timeout=timeout, ) + # Restrict the format of acceptable followup completions. for response in responses: + # remove leading and trailing periods completion = response.completion.strip('.') + if 'followup' in name and len(completion)>0: + if '?' in completion: # take first question that is found and only use the sentence before the question mark completion = completion.split('?')[0].split('.')[-1] @@ -109,7 +113,8 @@ async def run_step( # otherwise take the last sentence completion = completion.split('.')[-1].split('.')[-1] - response.completion = completion.strip() + '?' + # take maximum of 40 words + response.completion = ' '.join(completion.split(' ')[-40:]) + '?' # Compute the rewards for the responses given the prompt. From 92c79881f37943699ba9930af863df41758997e6 Mon Sep 17 00:00:00 2001 From: Steffen Cruz Date: Tue, 24 Oct 2023 10:26:12 -0600 Subject: [PATCH 3/3] Black --- prompting/validators/forward.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/prompting/validators/forward.py b/prompting/validators/forward.py index f79038d..3b9192f 100644 --- a/prompting/validators/forward.py +++ b/prompting/validators/forward.py @@ -100,22 +100,19 @@ async def run_step( # Restrict the format of acceptable followup completions. for response in responses: - # remove leading and trailing periods - completion = response.completion.strip('.') - - if 'followup' in name and len(completion)>0: + completion = response.completion.strip(".") - if '?' in completion: + if "followup" in name and len(completion) > 0: + if "?" in completion: # take first question that is found and only use the sentence before the question mark - completion = completion.split('?')[0].split('.')[-1] + completion = completion.split("?")[0].split(".")[-1] else: # otherwise take the last sentence - completion = completion.split('.')[-1].split('.')[-1] + completion = completion.split(".")[-1].split(".")[-1] # take maximum of 40 words - response.completion = ' '.join(completion.split(' ')[-40:]) + '?' - + response.completion = " ".join(completion.split(" ")[-40:]) + "?" # Compute the rewards for the responses given the prompt. rewards: torch.FloatTensor = torch.zeros(len(responses), dtype=torch.float32).to(