Skip to content

Commit 1dc66cf

Browse files
authored
Fix blank results (#788)
* handle blank results * unify how we detect blank results
1 parent 1b35aa0 commit 1dc66cf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

promptsource/templates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ def apply(self, example, truncate=True, highlight_variables=False) -> Tuple[str,
191191
# Splits on the separator, and then replaces back any occurrences of the
192192
# separator in the original example
193193
parts = [self._unescape_pipe(part).strip() for part in rendered_example.split("|||")]
194+
if parts == [""]:
195+
# Handles the case of blank results
196+
# Example: `tydiqa` where prompts are conditionned on the language and thus most of the time will return a blank result
197+
return parts
194198
if len(parts) < 2:
195199
raise ValueError("Prompt did not produce an input and at least one target.")
196200

test/show_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
print("\tExample ", example)
6363
print("\t--------")
6464
output = template.apply(example)
65-
if output[0].strip() == "" or (len(output) > 1 and output[1][0].strip() == ""):
65+
if output == [""]:
6666
print("\t Blank result")
6767
continue
6868

0 commit comments

Comments
 (0)