Datasets:
Upload AirQA.py with huggingface_hub
Browse files
AirQA.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
class AirQA(datasets.GeneratorBasedBuilder):
|
| 5 |
+
"""Example dataset loader for JSONL with selective fields and only test split."""
|
| 6 |
+
|
| 7 |
+
VERSION = datasets.Version("1.0.0")
|
| 8 |
+
|
| 9 |
+
def _info(self):
|
| 10 |
+
return datasets.DatasetInfo(
|
| 11 |
+
description="AirQA: A Comprehensive QA Dataset for AI Research with Instance-Level Evaluation",
|
| 12 |
+
features=datasets.Features({
|
| 13 |
+
"uuid": datasets.Value("string"),
|
| 14 |
+
"question": datasets.Value("string"),
|
| 15 |
+
"answer_format": datasets.Value("string"),
|
| 16 |
+
"anchor_pdf": datasets.Sequence(datasets.Value("string")),
|
| 17 |
+
"reference_pdf": datasets.Sequence(datasets.Value("string")),
|
| 18 |
+
"conference": datasets.Sequence(datasets.Value("string")),
|
| 19 |
+
}),
|
| 20 |
+
supervised_keys=None,
|
| 21 |
+
homepage="https://huggingface.co/datasets/OpenDFM/AirQA",
|
| 22 |
+
license="apache-2.0",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
def _split_generators(self, dl_manager):
|
| 26 |
+
files = dl_manager.download_and_extract({
|
| 27 |
+
"data": "data/test_data.jsonl",
|
| 28 |
+
"map": "data/uuid2title.json",
|
| 29 |
+
})
|
| 30 |
+
return [
|
| 31 |
+
datasets.SplitGenerator(
|
| 32 |
+
name=datasets.Split.TEST,
|
| 33 |
+
gen_kwargs={
|
| 34 |
+
"path": files["data"],
|
| 35 |
+
"map_path": files["map"],
|
| 36 |
+
},
|
| 37 |
+
)
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
def _generate_examples(self, path, map_path):
|
| 41 |
+
with open(map_path, encoding="utf-8") as f:
|
| 42 |
+
uuid2title = json.load(f)
|
| 43 |
+
|
| 44 |
+
keep_keys = ["uuid", "question", "answer_format", "anchor_pdf", "reference_pdf", "conference"]
|
| 45 |
+
|
| 46 |
+
def map_list(lst):
|
| 47 |
+
if lst is None:
|
| 48 |
+
return None
|
| 49 |
+
return [uuid2title.get(x, x) for x in lst]
|
| 50 |
+
|
| 51 |
+
with open(path, encoding="utf-8") as f:
|
| 52 |
+
for i, line in enumerate(f):
|
| 53 |
+
if not line.strip():
|
| 54 |
+
continue
|
| 55 |
+
ex = json.loads(line)
|
| 56 |
+
|
| 57 |
+
filtered = {k: ex.get(k, None) for k in keep_keys}
|
| 58 |
+
|
| 59 |
+
filtered["anchor_pdf"] = map_list(filtered["anchor_pdf"])
|
| 60 |
+
filtered["reference_pdf"] = map_list(filtered["reference_pdf"])
|
| 61 |
+
|
| 62 |
+
yield i, filtered
|