Skip to content

Fix blank results #788

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

Merged
merged 2 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions promptsource/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def apply(self, example, truncate=True, highlight_variables=False) -> Tuple[str,
# Splits on the separator, and then replaces back any occurrences of the
# separator in the original example
parts = [self._unescape_pipe(part).strip() for part in rendered_example.split("|||")]
if parts == [""]:
# Handles the case of blank results
# Example: `tydiqa` where prompts are conditionned on the language and thus most of the time will return a blank result
return parts
if len(parts) < 2:
raise ValueError("Prompt did not produce an input and at least one target.")

Expand Down
2 changes: 1 addition & 1 deletion test/show_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
print("\tExample ", example)
print("\t--------")
output = template.apply(example)
if output[0].strip() == "" or (len(output) > 1 and output[1][0].strip() == ""):
if output == [""]:
print("\t Blank result")
continue

Expand Down