Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict the format of acceptable followup completions #44

Merged
merged 5 commits into from
Oct 25, 2023
Merged
Changes from all 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
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