-
Notifications
You must be signed in to change notification settings - Fork 163
Add HotpotQA multi-hop QA benchmark #1292
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e820e93
Add MMLU-Pro 10% optimized subset for checkpoint selection (#1285)
ka00ri e4ff008
Add HotpotQA multi-hop QA benchmark
MahanFathi cf7334e
Support source_lang param for translation recipe (#1290)
prasoonvarshney 8e6a00c
Unify HotpotQA data preparation; copy-only for closedbook
MahanFathi 201c2d5
HotpotQA: metrics, prep, and filtering fixes
MahanFathi 13aef08
Fix pass@1[avg-of-k] variance display: scale ± to percentage in as_float
MahanFathi 9be6769
docs: update HotpotQA example results with latest run and variance
MahanFathi 25de92c
Address review: hotpotqa:4 in doc examples, comment for as_float std …
MahanFathi 85475d2
Use as_percentage for HotpotQA metrics; keep as_float for plain floats
MahanFathi 767ac24
Merge branch 'main' into mfathi/hotpotqa
MahanFathi 18e800c
Merge branch 'main' into mfathi/hotpotqa
Kipok 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
Some comments aren't visible on the classic Files Changed page.
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
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,17 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| METRICS_TYPE = "hotpotqa" | ||
| GENERATION_ARGS = "++prompt_config=eval/hotpotqa" | ||
| EVAL_SPLIT = "validation" |
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,24 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Prepare HotpotQA distractor validation set. Single source of truth for this data.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from nemo_skills.dataset.hotpotqa.prepare_utils import prepare_validation | ||
|
|
||
| if __name__ == "__main__": | ||
| data_dir = Path(__file__).absolute().parent | ||
| data_dir.mkdir(exist_ok=True) | ||
| prepare_validation(data_dir / "validation.jsonl") |
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,82 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use it except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Shared HotpotQA data formatting and preparation. | ||
|
|
||
| Used by both hotpotqa and hotpotqa_closedbook so there is a single source of truth | ||
| for downloading and formatting the distractor validation set. | ||
| """ | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from datasets import load_dataset | ||
| from tqdm import tqdm | ||
|
|
||
|
|
||
| def format_context(context: dict) -> str: | ||
| """Format context paragraphs with titles and indexed sentences. | ||
|
|
||
| Each paragraph becomes: | ||
| Title: <title> | ||
| [0] <sentence 0> | ||
| [1] <sentence 1> | ||
| ... | ||
|
|
||
| Paragraphs are separated by blank lines. | ||
| """ | ||
| paragraphs = [] | ||
| for title, sentences in zip(context["title"], context["sentences"], strict=True): | ||
| lines = [f"Title: {title}"] | ||
| for idx, sent in enumerate(sentences): | ||
| lines.append(f"[{idx}] {sent.strip()}") | ||
| paragraphs.append("\n".join(lines)) | ||
| return "\n\n".join(paragraphs) | ||
|
|
||
|
|
||
| def format_entry(entry: dict) -> dict: | ||
| """Format a HotpotQA entry to match NeMo-Skills format.""" | ||
| supporting_facts = list(zip(entry["supporting_facts"]["title"], entry["supporting_facts"]["sent_id"], strict=True)) | ||
|
|
||
| return { | ||
| "id": entry["id"], | ||
| "question": entry["question"], | ||
| "expected_answer": entry["answer"], | ||
| "context": format_context(entry["context"]), | ||
| "supporting_facts": supporting_facts, | ||
| "type": entry["type"], | ||
| "level": entry["level"], | ||
| } | ||
|
|
||
|
|
||
| def prepare_validation(output_path: Path) -> int: | ||
| """Download HotpotQA distractor validation set and write NeMo-Skills format to output_path. | ||
|
|
||
| Returns the number of examples written. | ||
| """ | ||
| output_path = Path(output_path) | ||
| output_path.parent.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| ds = load_dataset("hotpotqa/hotpot_qa", "distractor", split="validation") | ||
|
|
||
| formatted_entries = [format_entry(entry) for entry in tqdm(ds, desc=f"Formatting {output_path.name}")] | ||
| tmp_output_path = output_path.with_suffix(".jsonl.tmp") | ||
| with open(tmp_output_path, "wt", encoding="utf-8") as fout: | ||
| for formatted in formatted_entries: | ||
| json.dump(formatted, fout) | ||
| fout.write("\n") | ||
| tmp_output_path.replace(output_path) | ||
|
|
||
| print(f"Wrote {len(ds)} examples to {output_path}") | ||
| return len(ds) |
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,21 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Closed-book variant of HotpotQA: same questions, no context provided. | ||
| # Reuses the hotpotqa validation data (symlinked) with a different prompt | ||
| # and answer-only metrics. | ||
|
|
||
| METRICS_TYPE = "hotpotqa_closedbook" | ||
| GENERATION_ARGS = "++prompt_config=eval/hotpotqa_closedbook" | ||
| EVAL_SPLIT = "validation" |
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,42 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use it except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Closed-book variant uses the same validation data as hotpotqa (distractor setting). | ||
| # We reuse that file so there is only one real data preparation (in hotpotqa). | ||
|
|
||
| import shutil | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Reuse the shared preparation so we don't require hotpotqa to be prepared first. | ||
| from nemo_skills.dataset.hotpotqa.prepare_utils import prepare_validation | ||
|
|
||
| if __name__ == "__main__": | ||
| data_dir = Path(__file__).absolute().parent | ||
| data_dir.mkdir(exist_ok=True) | ||
| output_file = data_dir / "validation.jsonl" | ||
|
|
||
| hotpotqa_source = data_dir.parent / "hotpotqa" / "validation.jsonl" | ||
|
|
||
| if hotpotqa_source.exists(): | ||
| shutil.copy2(hotpotqa_source, output_file) | ||
| print(f"Copied {hotpotqa_source} -> {output_file}") | ||
| else: | ||
| # Same data; run shared preparation for hotpotqa then copy here. | ||
| prepare_validation(hotpotqa_source) | ||
| if not hotpotqa_source.exists(): | ||
| print("Preparation did not create the expected file.", file=sys.stderr) | ||
| sys.exit(1) | ||
| shutil.copy2(hotpotqa_source, output_file) | ||
| print(f"Copied {hotpotqa_source} -> {output_file}") |
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
Oops, something went wrong.
Oops, something went wrong.
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.