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

Add option to ignore casing in Includes eval template #655

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Move ignore_case logic to utils.get_answer function
  • Loading branch information
trizko committed Apr 12, 2023
commit bdb9b930e7262761054e4d6d644612fac2aa9703
7 changes: 3 additions & 4 deletions evals/elsuite/basic/includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ def eval_sample(self, sample: Any, *_):
prompt=prompt,
)
sampled = result.get_completions()[0]
if self.ignore_case:
sampled = sampled.lower()
sample["ideal"] = [ref.lower() for ref in sample["ideal"]]

includes_answer = any([utils.get_answer(sampled, ref) for ref in sample["ideal"]])
includes_answer = any(
[utils.get_answer(sampled, ref, self.ignore_case) for ref in sample["ideal"]]
)
evals.record.record_metrics(accuracy=float(includes_answer))
return includes_answer

Expand Down
8 changes: 6 additions & 2 deletions evals/elsuite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
)


def get_answer(text, answer_prompt):
idx = text.rfind(answer_prompt)
def get_answer(text, answer_prompt, ignore_case=False):
if ignore_case:
idx = text.lower().rfind(answer_prompt.lower())
else:
idx = text.rfind(answer_prompt)

if idx == -1:
return None
return text[idx + len(answer_prompt) :]
Expand Down