Skip to content

Commit

Permalink
Merge pull request #44 from opentensor/hotfix/short-followup
Browse files Browse the repository at this point in the history
Restrict the format of acceptable followup completions
  • Loading branch information
p-ferreira authored Oct 25, 2023
2 parents 08fd74c + 1b27790 commit 26dd7b7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions prompting/validators/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ async def run_step(
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]

# take maximum of 40 words
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(
self.device
Expand Down

0 comments on commit 26dd7b7

Please sign in to comment.