Skip to content

feat(scorers): add NamedScorer wrapper to support custom scorer names - #533

Open
nmath-goog wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
nmath-goog:feature-named-scorer
Open

feat(scorers): add NamedScorer wrapper to support custom scorer names#533
nmath-goog wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
nmath-goog:feature-named-scorer

Conversation

@nmath-goog

@nmath-goog nmath-goog commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Introduces the NamedScorer wrapper class to support custom top-level YAML keys in run configurations (e.g. rubric_pass_fail: {type: python_scorer}).

Summary of Changes

  1. NamedScorer Wrapper (evalbench/scorers/namedscorer.py):
  • A lightweight Comparator wrapper that stores the custom metric name (name) and delegates compare(...) to its base_scorer.
  1. Resolution Logic in score.py (evalbench/scorers/score.py):
  • get_scorer_instance checks if a YAML key exists in DEFAULT_SCORERS. If not, it inspects the type: attribute (e.g., rubric_pass_fail: {type: python_scorer, script_path: ...}) or nested dictionary (rubric_validator: {python_scorer: ...}) and wraps the underlying comparator in NamedScorer.
  1. Summary Reporting in analyzer.py (evalbench/reporting/analyzer.py):
  • Dynamically includes custom named comparators from df["comparator"] in summary reports.

Test Plan & Verification

  1. NamedScorer Unit Tests (evalbench/test/named_python_scorer_test.py):
  • test_type_python_scorer_and_nested_dict: Tests configuration resolution for custom top-level keys using both type: python_scorer attribute syntax and nested dictionary syntax.
  • test_named_scorer_wrapper: Verifies delegation of compare() calls and metric name property forwarding.
  1. Resolution & Execution Tests in score_test.py (evalbench/test/score_test.py):
  • test_get_scorer_instance_named_scorer_type_attr: Asserts get_scorer_instance returns a NamedScorer wrapping PythonScorer for top-level keys specifying type: python_scorer.
  • test_get_scorer_instance_named_scorer_nested_dict: Asserts get_scorer_instance returns a NamedScorer for nested dictionary declarations.
  • test_score_compare_execution: Asserts score.compare(...) executes named comparators and correctly sets comparator = custom_name in output results.
  1. Full Suite Execution:
  • All test cases passed.

@nmath-goog
nmath-goog force-pushed the feature-named-scorer branch 6 times, most recently from a607991 to 27cb201 Compare July 31, 2026 22:41
@nmath-goog
nmath-goog force-pushed the feature-named-scorer branch 2 times, most recently from 44ecaa6 to d5897c3 Compare August 4, 2026 22:28
@prernakakkar-google

Copy link
Copy Markdown
Collaborator

/gcbrun

@nmath-goog
nmath-goog force-pushed the feature-named-scorer branch from 81c859b to 5d51300 Compare August 5, 2026 17:45
Value proposition / Summary of Changes:
- Introduces NamedScorer (evalbench/scorers/namedscorer.py), a wrapper around Comparator that encapsulates custom metric names defined in YAML configs.
- Updates get_scorer_instance in evalbench/scorers/score.py to recognize custom/non-default scorer names (e.g. type: python_scorer or nested dicts) and wrap them with NamedScorer.
- Updates evalbench/reporting/analyzer.py to dynamically resolve metric names and aggregate sub-comparators cleanly.

Test Plan & Verification:
- Unit tests added in evalbench/test/named_python_scorer_test.py and evalbench/test/score_test.py.
- Ran pycodestyle (0 errors) and pytest test suite.

TAG=agy
CONV=fa97fdc6-3cc9-4993-894b-95e74d57a73d
@nmath-goog
nmath-goog force-pushed the feature-named-scorer branch 2 times, most recently from 506518f to 893f60e Compare August 5, 2026 18:19

@nmath-goog nmath-goog left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/gcbrun

@graceqi-g

Copy link
Copy Markdown
Collaborator

/gcbrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants