pubmed / make_dataset.py
kardosdrur's picture
Added code generating the dataset
570a98a verified
raw
history blame contribute delete
558 Bytes
from ast import literal_eval
from datasets import Dataset, load_dataset
pm = load_dataset(
"owaiskha9654/PubMed_MultiLabel_Text_Classification_Dataset_MeSH", split="train"
)
records = []
for t, lab in zip(pm["abstractText"], pm["meshMajor"]):
try:
labels = literal_eval(lab)
labels = labels[:2]
records.append({"text": t, "label": labels})
except Exception:
print("Couldn't add entry:", lab)
ds = Dataset.from_list(records)
ds = ds.train_test_split(test_size=0.2, seed=42)
ds.push_to_hub("kardosdrur/pubmed")