-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
32 deletions.
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
35 changes: 35 additions & 0 deletions
35
llama_stack/providers/impls/meta_reference/evals/scorer/aggregate_scorer.py
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,35 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the terms described in the LICENSE file in | ||
# the root directory of this source tree. | ||
from llama_stack.apis.evals.evals import BaseScorer, EvalResult, SingleEvalResult | ||
from llama_stack.apis.datasets.datasets import * # noqa: F401 F403 | ||
|
||
|
||
class AggregateScorer(BaseScorer[ScorerInputSample]): | ||
def __init__(self, scorers: List[BaseScorer[ScorerInputSample]]): | ||
self.scorers = scorers | ||
|
||
def score_sample(self, scorer_input_sample: ScorerInputSample) -> SingleEvalResult: | ||
all_score_data = {} | ||
for scorer in self.scorers: | ||
score_data = scorer.score_sample(scorer_input_sample).score_data | ||
for k, v in score_data.items(): | ||
all_score_data[k] = v | ||
|
||
return SingleEvalResult( | ||
score_data=all_score_data, | ||
) | ||
|
||
def aggregate_results(self, eval_results: List[SingleEvalResult]) -> EvalResult: | ||
all_metrics = {} | ||
|
||
for scorer in self.scorers: | ||
metrics = scorer.aggregate_results(eval_results).metrics | ||
for k, v in metrics.items(): | ||
all_metrics[f"{scorer.__class__.__name__}:{k}"] = v | ||
|
||
return EvalResult( | ||
metrics=all_metrics, | ||
) |
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