|
|
import os |
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
|
# (Optional) Add your citation here |
|
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
|
NLGraph: A collection of graph-related tasks with natural language representations. |
|
|
Each subset corresponds to a task (e.g., connectivity, cycle, shortest_path). |
|
|
Each split contains examples stored in JSON Lines format. |
|
|
""" |
|
|
|
|
|
|
|
|
TASKS = [ |
|
|
"connectivity", |
|
|
"cycle", |
|
|
"flow", |
|
|
"GNN", |
|
|
"hamilton", |
|
|
"matching", |
|
|
"shortest_path", |
|
|
"topology", |
|
|
] |
|
|
|
|
|
class NLGraphConfig(datasets.BuilderConfig): |
|
|
def __init__(self, task_name, **kwargs): |
|
|
super().__init__(name=task_name, **kwargs) |
|
|
self.task_name = task_name |
|
|
|
|
|
|
|
|
class NLGraph(datasets.GeneratorBasedBuilder): |
|
|
BUILDER_CONFIGS = [ |
|
|
NLGraphConfig(task_name=task) for task in TASKS |
|
|
] |
|
|
|
|
|
def _info(self): |
|
|
return datasets.DatasetInfo( |
|
|
description=_DESCRIPTION, |
|
|
features=datasets.Features({ |
|
|
"question": datasets.Value("string"), |
|
|
"answer": datasets.Value("string"), |
|
|
"difficulty": datasets.Value("string"), |
|
|
"doc_id": datasets.Value("string"), |
|
|
|
|
|
}), |
|
|
supervised_keys=None, |
|
|
homepage="https://huggingface.co/datasets/huayangli/nlgraph", |
|
|
citation=_CITATION, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
data_files = { |
|
|
"test": dl_manager.download_and_extract(os.path.join(self.config.name, "test.jsonl")), |
|
|
"train": dl_manager.download_and_extract(os.path.join(self.config.name, "train.jsonl")), |
|
|
} |
|
|
return [ |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TRAIN, |
|
|
gen_kwargs={"filepath": data_files['train']}, |
|
|
), |
|
|
datasets.SplitGenerator( |
|
|
name=datasets.Split.TEST, |
|
|
gen_kwargs={"filepath": data_files['test']}, |
|
|
), |
|
|
] |
|
|
|
|
|
def _generate_examples(self, filepath): |
|
|
import json |
|
|
with open(filepath, "r", encoding="utf-8") as f: |
|
|
for idx, line in enumerate(f): |
|
|
data = json.loads(line) |
|
|
yield idx, data |
|
|
|