Datasets:
kardosdrur
commited on
Added code generating the dataset
Browse files- make_dataset.py +21 -0
make_dataset.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ast import literal_eval
|
2 |
+
|
3 |
+
from datasets import Dataset, load_dataset
|
4 |
+
|
5 |
+
pm = load_dataset(
|
6 |
+
"owaiskha9654/PubMed_MultiLabel_Text_Classification_Dataset_MeSH", split="train"
|
7 |
+
)
|
8 |
+
|
9 |
+
records = []
|
10 |
+
for t, lab in zip(pm["abstractText"], pm["meshMajor"]):
|
11 |
+
try:
|
12 |
+
labels = literal_eval(lab)
|
13 |
+
labels = labels[:2]
|
14 |
+
records.append({"text": t, "label": labels})
|
15 |
+
except Exception:
|
16 |
+
print("Couldn't add entry:", lab)
|
17 |
+
|
18 |
+
ds = Dataset.from_list(records)
|
19 |
+
ds = ds.train_test_split(test_size=0.2, seed=42)
|
20 |
+
|
21 |
+
ds.push_to_hub("kardosdrur/pubmed")
|