Skip to content

Add Classification Evaluator unit test #2838

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

Merged
merged 8 commits into from
Jul 15, 2025
Merged

Conversation

fzowl
Copy link
Contributor

@fzowl fzowl commented Jun 20, 2025

First step in resolving the #1955 issue.

@fzowl fzowl changed the title Adding Classification Evaluator test Add Classification Evaluator unit test Jun 20, 2025
Copy link
Contributor

@KennethEnevoldsen KennethEnevoldsen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Generally I think this looks really well, but I think we can simplify it down a bit.

In v2 we combine these into a single ClassificationEvaluator (to prevent discrepancies across), which has a classifier (sklearn interface) attached. This classifier will by default be logistic, but in principle you could change it out with any sklearn compatible classifier.

("eval_logreg_multiclass", False),
],
)
def test_output_structure(self, evaluator_fixture, is_binary, model, request):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably change this to:

Suggested change
def test_output_structure(self, evaluator_fixture, is_binary, model, request):
def test_binary_output_structure(self, evaluator, model, x_train: list[str], y_train: list[int], x_test, x_train, expected_score: float):

That way, you can parametrize both the model and the evaluator - you will initialize the evaluator a few more times than you do now, but this way it is very easy to add new test cases. You can also extract whether the task is binary or not from the labels.

Note that it might be easier to define:

ClassificationTestCase:
  x_train: list[str]
  y_train: list[int]
  x_test
  x_train
  expected_score: float

# which leads to:  
def test_binary_output_structure(self, evaluator, model, testcase: ClassificationTestCase):

Copy link
Contributor

Choose a reason for hiding this comment

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

We naturally can't check for the expected output here with the random MockNumpyEncoder(), however, changing it to:

class MockNumpyEncoder(mteb.Encoder):
    def __init__(self):
        self.rng_state = np.random.default_rng(42)

    def encode(self, sentences, prompt_name: str | None = None, **kwargs):
        return self.rng_state.random.rand(len(sentences), 10)

should fix the issue and should not introduce new issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KennethEnevoldsen I refactored this a bit, can you please take a look?

@fzowl fzowl requested a review from KennethEnevoldsen June 26, 2025 16:54
@fzowl
Copy link
Contributor Author

fzowl commented Jun 26, 2025

@KennethEnevoldsen Thank you for the review! Can you please take another look now if the test is better this time?

Copy link
Contributor

@KennethEnevoldsen KennethEnevoldsen left a comment

Choose a reason for hiding this comment

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

Looking a lot better - Added a few simplifications to make it simpler

@fzowl
Copy link
Contributor Author

fzowl commented Jul 9, 2025

@KennethEnevoldsen Can you please take a look now?

@fzowl fzowl requested a review from KennethEnevoldsen July 9, 2025 16:51
@fzowl fzowl requested a review from Samoed July 14, 2025 21:51
@Samoed Samoed merged commit 4a47f90 into embeddings-benchmark:main Jul 15, 2025
9 checks passed
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