import gzip import json import datasets _URLS = { "csl": "https://huggingface.co/datasets/neuclir/csl/resolve/main/data/csl.jsonl.gz" } class Csl(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.0.0") def _info(self): return datasets.DatasetInfo( features=datasets.Features({ "doc_id": datasets.Value("string"), "title": datasets.Value("string"), "abstract": datasets.Value("string"), "keywords": datasets.Sequence(feature=datasets.Value("string"), length=-1), "category": datasets.Value("string"), "category_zho": datasets.Value("string"), "discipline": datasets.Value("string"), "discipline_zho": datasets.Value("string"), }), ) def _split_generators(self, dl_manager): paths = dl_manager.download(_URLS) return [ datasets.SplitGenerator( name='csl', gen_kwargs={ "filepath": paths['csl'], }) ] def _generate_examples(self, filepath): with gzip.open(filepath) as f: for key, row in enumerate(f): data = json.loads(row) yield key, data