Skip to content

Fix InformationRetrievalEvaluator prediction export when output_path does not exist#3659

Merged
tomaarsen merged 3 commits into
huggingface:mainfrom
ignasgr:fix-ir-eval-write-predictions
Feb 17, 2026
Merged

Fix InformationRetrievalEvaluator prediction export when output_path does not exist#3659
tomaarsen merged 3 commits into
huggingface:mainfrom
ignasgr:fix-ir-eval-write-predictions

Conversation

@ignasgr

@ignasgr ignasgr commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a bug in InformationRetrievalEvaluator where prediction file writing could fail when write_predictions=True and the provided output_path did not already exist.

Root Cause

compute_metrices()writes prediction JSONL files, but directory creation for output_path occurs after compute_metrices() is called within __call__().

Changes

  • Create directory within compute_metrices() before file is written

Minimal Example

from sentence_transformers import SentenceTransformer
from sentence_transformers.evaluation import InformationRetrievalEvaluator

model = SentenceTransformer("all-MiniLM-L6-v2")

queries = {
    "q1": "who is alfie",
    "q2": "which pet is maple",
    "q3": "tell me about poplar",
}

corpus = {
    "d1": "Alfie is a playful dog who likes long walks and tennis balls.",
    "d2": "Maple is a calm orange cat who naps in sunny windows.",
    "d3": "Poplar is a curious gray cat who chases toy mice at night.",
    "d4": "Alfie the dog enjoys treats after learning new tricks.",
    "d5": "Maple the cat loves soft blankets and quiet afternoons.",
    "d6": "Poplar the cat likes climbing shelves and watching birds.",
}

relevant_docs = {
    "q1": {"d1", "d4"},
    "q2": {"d2", "d5"},
    "q3": {"d3", "d6"},
}

ir_evaluator = InformationRetrievalEvaluator(
    queries=queries,
    corpus=corpus,
    relevant_docs=relevant_docs,
    write_predictions=True,
)

out_dir = "./output"
ir_evaluator(model, output_path=out_dir)  # this would fail before

@tomaarsen

Copy link
Copy Markdown
Member

Hello!

This is great, thanks for spotting and resolving it. I wanted to quickly reproduce it with the snippet in the docs, but then I noticed it was a bit dated and the dataset can't be loaded anymore. So, I replaced the docs snippet slightly.

I think this is all ready to go! I also pulled main as #3664 is required for the tests to pass due to the new transformers v5.2 release. I'll merge this once these tests pass as well. Thank you!

  • Tom Aarsen

@tomaarsen tomaarsen enabled auto-merge (squash) February 17, 2026 13:01
@tomaarsen tomaarsen merged commit f2ab4d7 into huggingface:main Feb 17, 2026
17 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.

2 participants