-
Notifications
You must be signed in to change notification settings - Fork 566
dataset: Add miracl vision #2736
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
isaac-chung
merged 15 commits into
embeddings-benchmark:main
from
ManuelFay:add-miracl-vision
Jun 6, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2f60d20
add miracl vision
ManuelFay 5cf545c
add miracl vision
ManuelFay 0895307
ruff
ManuelFay 05dca31
cast
ManuelFay f5d4843
image
ManuelFay 8b664e8
image
ManuelFay a40f50a
add langs
ManuelFay dc4efdc
add langs
ManuelFay 50faa27
add langs
ManuelFay db3b0ae
add langs
ManuelFay 2fca089
descriptive stats
ManuelFay 03bdfa0
lint
ManuelFay c9e99d4
lint
ManuelFay 6ea635f
lint
ManuelFay d381d06
remove com
ManuelFay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
178 changes: 178 additions & 0 deletions
178
mteb/tasks/Image/Any2AnyRetrieval/multilingual/MIRACLVisionRetrieval.py
This file contains hidden or 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,178 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import datasets | ||
|
|
||
| from mteb.abstasks.Image.AbsTaskAny2AnyRetrieval import AbsTaskAny2AnyRetrieval | ||
| from mteb.abstasks.MultilingualTask import MultilingualTask | ||
| from mteb.abstasks.TaskMetadata import TaskMetadata | ||
|
|
||
| _EVAL_SPLIT = "default" | ||
|
|
||
| _LANGUAGES = { | ||
| "ar": ["ara-Arab"], | ||
| "bn": ["ben-Beng"], | ||
| "de": ["deu-Latn"], | ||
| "en": ["eng-Latn"], | ||
| "es": ["spa-Latn"], | ||
| "fa": ["fas-Arab"], | ||
| "fi": ["fin-Latn"], | ||
| "fr": ["fra-Latn"], | ||
| "hi": ["hin-Deva"], | ||
| "id": ["ind-Latn"], | ||
| "ja": ["jpn-Jpan"], | ||
| "ko": ["kor-Kore"], | ||
| "ru": ["rus-Cyrl"], | ||
| "sw": ["swa-Latn"], | ||
| "te": ["tel-Telu"], | ||
| "th": ["tha-Thai"], | ||
| "yo": ["yor-Latn"], | ||
| "zh": ["zho-Hans"], | ||
| } | ||
|
|
||
|
|
||
| def _load_miracl_data( | ||
| path: str, | ||
| langs: list, | ||
| splits: str, | ||
| cache_dir: str | None = None, | ||
| revision: str | None = None, | ||
| trust_remote_code: bool = False, | ||
| ): | ||
| corpus = {lang: dict.fromkeys(splits) for lang in langs} | ||
| queries = {lang: dict.fromkeys(splits) for lang in langs} | ||
| relevant_docs = {lang: dict.fromkeys(splits) for lang in langs} | ||
|
|
||
| split = _EVAL_SPLIT | ||
|
|
||
| for lang in langs: | ||
| # Load corpus data (Can be several millions for languages) | ||
| corpus_identifier = f"corpus-{lang}" | ||
| corpus_data = datasets.load_dataset( | ||
| path, | ||
| corpus_identifier, | ||
| cache_dir=cache_dir, | ||
| revision=revision, | ||
| trust_remote_code=trust_remote_code, | ||
| ) | ||
|
|
||
| images_identifier = f"images-{lang}" | ||
| images_data = datasets.load_dataset( | ||
| path, | ||
| images_identifier, | ||
| cache_dir=cache_dir, | ||
| revision=revision, | ||
| trust_remote_code=trust_remote_code, | ||
| ) | ||
|
|
||
| # For text data, it would look like this, just use _id column | ||
|
|
||
| imgid2docid = { | ||
| str(ex["image_id"]): str(ex["_id"]) | ||
| for ex in corpus_data[split] # e.g. “train”, “validation”, etc. | ||
| } | ||
|
|
||
| images_data = images_data.map( | ||
| lambda x: { | ||
| "id": imgid2docid[str(x["file_name"])], | ||
| # "modality": "text", | ||
| "modality": "image", | ||
| "text": None, | ||
| }, | ||
| remove_columns=["file_name"], | ||
| ) | ||
|
|
||
| corpus[lang][split] = images_data[split] | ||
|
|
||
| # Load queries data | ||
| queries_identifier = f"queries-{lang}" | ||
| queries_data = datasets.load_dataset( | ||
| path, | ||
| queries_identifier, | ||
| cache_dir=cache_dir, | ||
| revision=revision, | ||
| trust_remote_code=trust_remote_code, | ||
| ) | ||
| queries_data = queries_data.map( | ||
| lambda x: { | ||
| "id": str(x["_id"]), | ||
| "text": x["text"], | ||
| "modality": "text", | ||
| "image": None, | ||
| }, | ||
| remove_columns=["_id"], | ||
| ) | ||
| queries[lang][split] = queries_data[split] | ||
|
|
||
| # Load relevant documents data | ||
| qrels_identifier = f"qrels-{lang}" | ||
| qrels_data = datasets.load_dataset( | ||
| path, | ||
| qrels_identifier, | ||
| cache_dir=cache_dir, | ||
| revision=revision, | ||
| trust_remote_code=trust_remote_code, | ||
| ) | ||
| relevant_docs[lang][split] = {} | ||
| for row in qrels_data[split]: | ||
| query_id = str(row["query-id"]) | ||
| doc_id = str(row["corpus-id"]) | ||
| score = row["score"] | ||
| if query_id not in relevant_docs[lang][split]: | ||
| relevant_docs[lang][split][query_id] = {} | ||
| relevant_docs[lang][split][query_id][doc_id] = score | ||
|
|
||
| corpus = datasets.DatasetDict(corpus) | ||
| queries = datasets.DatasetDict(queries) | ||
| relevant_docs = datasets.DatasetDict(relevant_docs) | ||
|
|
||
| return corpus, queries, relevant_docs | ||
|
|
||
|
|
||
| class MIRACLVisionRetrieval(MultilingualTask, AbsTaskAny2AnyRetrieval): | ||
| metadata = TaskMetadata( | ||
| name="MIRACLVisionRetrieval", | ||
| description="Retrieve associated pages according to questions.", | ||
| reference="https://arxiv.org/pdf/2407.01449", | ||
| dataset={ | ||
| "path": "nvidia/miracl-vision", | ||
| "revision": "309e1696433408fbd555959cf1da968f3814f8b6", | ||
| }, | ||
| type="DocumentUnderstanding", | ||
| category="t2i", | ||
| eval_splits=["default"], | ||
| eval_langs=_LANGUAGES, | ||
| main_score="ndcg_at_5", | ||
| date=("2025-03-01", "2025-06-01"), | ||
| domains=["Encyclopaedic"], | ||
| task_subtypes=["Image Text Retrieval"], | ||
| license="cc-by-sa-4.0", | ||
| annotations_creators="derived", | ||
| dialect=[], | ||
| modalities=["text", "image"], | ||
| sample_creation="created", | ||
| bibtex_citation=r""" | ||
| @article{osmulski2025miraclvisionlargemultilingualvisual, | ||
| author = {Radek Osmulski and Gabriel de Souza P. Moreira and Ronay Ak and Mengyao Xu and Benedikt Schifferer and Even Oldridge}, | ||
| eprint = {2505.11651}, | ||
| journal = {arxiv}, | ||
| title = {{MIRACL-VISION: A Large, multilingual, visual document retrieval benchmark}}, | ||
| url = {https://arxiv.org/abs/2505.11651}, | ||
| year = {2025}, | ||
| } | ||
| """, | ||
| prompt={"query": "Find a screenshot that is relevant to the user's query."}, | ||
| ) | ||
|
|
||
| def load_data(self, **kwargs): | ||
| if self.data_loaded: | ||
| return | ||
|
|
||
| self.corpus, self.queries, self.relevant_docs = _load_miracl_data( | ||
| path=self.metadata_dict["dataset"]["path"], | ||
| splits=self.metadata_dict["eval_splits"], | ||
| langs=self.hf_subsets, | ||
| cache_dir=kwargs.get("cache_dir", None), | ||
| revision=self.metadata_dict["dataset"]["revision"], | ||
| ) | ||
|
|
||
| self.data_loaded = True | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.