forked from openai/evals
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[unit test] Adding unit test for metrics.get_accuracy (openai#224)
Adding a unit test to get the ball rolling, starting with metrics since they are fundamental to evaluating performance. :) It would be great to add some more tests when building out more, and also enable CI (e.g., via GitHub actions). This also fixes an unused param to `get_bootstrap_accuracy_std`.
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ dependencies = [ | |
"pyyaml", | ||
"sacrebleu", | ||
"matplotlib", | ||
"pytest", | ||
"setuptools_scm", | ||
"langchain" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import List | ||
from unittest.mock import MagicMock | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from evals import metrics | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"event_labels, expected", | ||
[ | ||
([True, True], 1.0), | ||
([True, False, False], 0.333), | ||
([False, False], 0.0), | ||
([], np.nan), | ||
], | ||
) | ||
def test_get_accuracy( | ||
event_labels: List[bool], | ||
expected: float, | ||
) -> None: | ||
events = [MagicMock(data={"correct": value}) for value in event_labels] | ||
np.testing.assert_allclose(expected, metrics.get_accuracy(events), rtol=1e-3) |