Skip to content
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

[DRAFT] tests for nanobeir evaluator #3127

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions tests/test_nanobeir_evaluator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import annotations

import pytest

from sentence_transformers import SentenceTransformer
from sentence_transformers.evaluation import NanoBEIREvaluator


def test_nanobeir_evaluator():
"""Tests that the NanoBERTEvaluator can be loaded and produces expected metrics"""
datasets = ["QuoraRetrieval", "MSMARCO"]
query_prompts = {
"QuoraRetrieval": "Instruct: Given a question, retrieve questions that are semantically equivalent to the given question\\nQuery: ",
"MSMARCO": "Instruct: Given a web search query, retrieve relevant passages that answer the query\\nQuery: "
}

model = SentenceTransformer("sentence-transformers-testing/stsb-bert-tiny-safetensors")

evaluator = NanoBEIREvaluator(
dataset_names=datasets,
query_prompts=query_prompts,
)

results = evaluator(model)

assert len(results) > 0
assert all(isinstance(results[metric], float) for metric in results)

# def test_nanobeir_evaluator_with_invalid_dataset():
# """Test that NanoBEIREvaluator raises an error for invalid dataset names."""
# invalid_datasets = ["invalidDataset"]

# with pytest.raises(ValueError, match=f"Dataset(s) {invalid_datasets} not found in the NanoBEIR collection.Valid dataset names are: ['climatefever', 'dbpedia', 'fever', 'fiqa2018', 'hotpotqa', 'msmarco', 'nfcorpus', 'nq', 'quoraretrieval', 'scidocs', 'arguana', 'scifact', 'touche2020']"):
# NanoBEIREvaluator(
# dataset_names=invalid_datasets,
# )

# def test_nanobeir_evaluator_empty_inputs():
# """Test that NanoBEIREvaluator behaves correctly with empty datasets."""
# with pytest.raises(ValueError, match="dataset_names cannot be empty. Use None to evaluate on all datasets."):
# NanoBEIREvaluator(
# dataset_names=[],
# )
Loading