Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/evaluate/evaluator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
integer will run the model on the associated CUDA device ID. If `None` is provided it will be inferred and
CUDA:0 used if available, CPU otherwise.
random_state (`int`, *optional*, defaults to `None`):
The `random_state` value passed to `bootstrap` if `"bootstrap"` strategy is chosen. Useful for
debugging.
The `random_state` value passed to `bootstrap` if `"bootstrap"` strategy is chosen. If `None`, a fixed
seed of 0 is used, so the same inputs give the same confidence interval on every run.
"""

EVALUATOR_COMPUTE_RETURN_DOCSTRING = r"""
Expand Down Expand Up @@ -134,6 +134,9 @@ def _compute_confidence_interval(
A utility function enabling the confidence interval calculation for metrics computed
by the evaluator based on `scipy`'s `bootstrap` method.
"""
if random_state is None:
# Seed by default, so the same predictions give the same interval on every run.
random_state = 0

# bootstrap only works with functions that use args and no kwargs
def build_args_metric(metric, key, **kwargs):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,23 @@ def test_bootstrap(self):
self.assertAlmostEqual(results["accuracy"]["confidence_interval"][1], 1.0, 5)
self.assertAlmostEqual(results["accuracy"]["standard_error"], 0.22498, 5)

def test_bootstrap_is_reproducible_without_random_state(self):
data = Dataset.from_dict({"label": [1, 0, 0], "text": ["great movie", "great movie", "horrible movie"]})

def run():
return self.evaluator.compute(
model_or_pipeline=self.pipe,
data=data,
metric="accuracy",
label_mapping=self.label_mapping,
strategy="bootstrap",
n_resamples=10,
)["accuracy"]

first, second = run(), run()
self.assertEqual(first["confidence_interval"], second["confidence_interval"])
self.assertEqual(first["standard_error"], second["standard_error"])

def test_perf(self):
results = self.evaluator.compute(
model_or_pipeline=self.perf_pipe,
Expand Down