|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
import glob |
|
|
|
import datasets |
|
from datasets.data_files import DataFilesDict |
|
from .scirepeval_configs import SCIREPEVAL_CONFIGS |
|
|
|
from datasets.utils.logging import get_logger |
|
|
|
|
|
logger = get_logger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {A great new dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2021} |
|
} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve this great NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
"first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip", |
|
"second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip", |
|
} |
|
|
|
|
|
|
|
|
|
class Scirepeval(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = SCIREPEVAL_CONFIGS |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
|
|
description=self.config.description, |
|
|
|
features=datasets.Features(self.config.features), |
|
|
|
|
|
|
|
|
|
homepage="", |
|
|
|
license=self.config.license, |
|
|
|
citation=self.config.citation, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
base_url = "https://ai2-s2-research-public.s3.us-west-2.amazonaws.com/scirepeval" |
|
data_urls = dict() |
|
data_dir = self.config.url if self.config.url else self.config.name |
|
if self.config.is_training: |
|
data_urls = {"train": f"{base_url}/train/{data_dir}/train.jsonl"} |
|
|
|
if "refresh" not in self.config.name: |
|
data_urls.update({"val": f"{base_url}/train/{data_dir}/val.jsonl"}) |
|
|
|
if "cite_prediction" not in self.config.name: |
|
data_urls.update({"test": f"{base_url}/test/{data_dir}/meta.jsonl"}) |
|
|
|
downloaded_files = dl_manager.download_and_extract(data_urls) |
|
|
|
splits = [] |
|
if "test" in downloaded_files: |
|
splits = [datasets.SplitGenerator( |
|
name=datasets.Split("evaluation"), |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["test"], |
|
"split": "evaluation" |
|
}, |
|
), |
|
] |
|
|
|
if "train" in downloaded_files: |
|
splits.append( |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["train"], |
|
"split": "train", |
|
}, |
|
)) |
|
if "val" in downloaded_files: |
|
splits.append(datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["val"], |
|
"split": "validation", |
|
})) |
|
return splits |
|
|
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
def read_data(data_path): |
|
task_data = [] |
|
try: |
|
task_data = json.load(open(data_path, "r", encoding="utf-8")) |
|
except: |
|
with open(data_path) as f: |
|
task_data = [json.loads(line) for line in f] |
|
if type(task_data) == dict: |
|
task_data = list(task_data.values()) |
|
return task_data |
|
|
|
|
|
|
|
seen_keys = set() |
|
IGNORE=set(["n_key_citations", "session_id", "user_id", "user"]) |
|
logger.warning(filepath) |
|
with open(filepath, encoding="utf-8") as f: |
|
for line in f: |
|
d = json.loads(line) |
|
d = {k:v for k,v in d.items() if k not in IGNORE} |
|
key="doc_id" if "cite_prediction_" not in self.config.name else "corpus_id" |
|
if self.config.task_type == "proximity": |
|
if "cite_prediction" in self.config.name: |
|
if "arxiv_id" in d["query"]: |
|
for item in ["query", "pos", "neg"]: |
|
del d[item]["arxiv_id"] |
|
del d[item]["doi"] |
|
if "fos" in d["query"]: |
|
del d["query"]["fos"] |
|
if "score" in d["pos"]: |
|
del d["pos"]["score"] |
|
yield str(d["query"][key]) + str(d["pos"][key]) + str(d["neg"][key]), d |
|
else: |
|
if d["query"][key] not in seen_keys: |
|
seen_keys.add(d["query"][key]) |
|
yield str(d["query"][key]), d |
|
else: |
|
if d[key] not in seen_keys: |
|
seen_keys.add(d[key]) |
|
if self.config.task_type != "search": |
|
if "corpus_id" not in d: |
|
d["corpus_id"] = None |
|
if "scidocs" in self.config.name: |
|
if "cited by" not in d: |
|
d["cited_by"] = [] |
|
if type(d["corpus_id"]) == str: |
|
d["corpus_id"] = None |
|
yield d[key], d |