|
|
|
"""CogText Dataset""" |
|
|
|
import datasets |
|
import pandas as pd |
|
|
|
|
|
_CITATION = """\ |
|
@misc{cogtext2022, |
|
author = {Morteza Ansarinia and |
|
Paul Schrater and |
|
Pedro Cardoso-Leite}, |
|
title = {Linking Theories and Methods in Cognitive Sciences via Joint Embedding of the Scientific Literature: The Example of Cognitive Control}, |
|
year = {2022}, |
|
url = {https://arxiv.org/abs/2203.11016} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
CogText dataset contains a collection of PubMed abstracts, along with their GPT-3 embeddings and topic embeddings. |
|
""" |
|
_HOMEPAGE = "https://github.com/morteza/cogtext" |
|
_LICENSE = "CC-BY-4.0" |
|
|
|
_URLS = [ |
|
"pubmed/abstracts.csv.gz" |
|
] |
|
|
|
|
|
class CogText(datasets.GeneratorBasedBuilder): |
|
"""S collection of PubMed abstracts, along with their GPT-3 embeddings and topic embeddings.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_CONFIG_NAME = "abstracts" |
|
|
|
def _info(self): |
|
|
|
|
|
features = datasets.Features( |
|
{ |
|
"pmid": datasets.Value("int32"), |
|
"doi": datasets.Value("string"), |
|
"year": datasets.Value("int32"), |
|
"journal_title": datasets.Value("string"), |
|
"journal_iso_abbreviation": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"abstract": datasets.Value("string"), |
|
"category": datasets.Value("string"), |
|
"subcategory": datasets.Value("string"), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=("abstract", "subcategory"), |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
[abstracts_path] = dl_manager.download(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split("abstracts"), |
|
|
|
gen_kwargs={ |
|
"filepath": abstracts_path, |
|
"split": "abstracts", |
|
}, |
|
) |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
|
|
|
|
example_df = pd.read_csv(filepath, compression="gzip") |
|
|
|
for key, row in example_df.iterrows(): |
|
yield key, { |
|
"pmid": row['pmid'], |
|
"year": row['year'], |
|
"journal_title": row['journal_title'], |
|
"journal_iso_abbreviation": row['journal_iso_abbreviation'], |
|
'category': row['category'], |
|
'subcategory': row['subcategory'], |
|
'doi': row['doi'], |
|
'title': row['title'], |
|
'abstract': row['abstract'], |
|
} |
|
|