qanastek commited on
Commit
bd90170
1 Parent(s): 007990b

Upload 2 files

Browse files
Files changed (2) hide show
  1. morfitt.py +118 -0
  2. test_dataset.py +14 -0
morfitt.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """MORFITT: A multi-label corpus of French biomedical literature"""
16
+
17
+ import os
18
+ import json
19
+
20
+ import datasets
21
+
22
+ _DESCRIPTION = """\
23
+ We introduce MORFITT corpus, the first multi-label corpus for the classification of specialties in the medical field in French. MORFITT is composed of 3,624 summaries of scientific articles from PubMed, annotated in 12 specialties. The article details the corpus, the experiments and the preliminary results obtained using a classifier based on the pre-trained language model CamemBERT.
24
+ """
25
+
26
+ _HOMEPAGE = "https://github.com/qanastek/MORFITT"
27
+
28
+ _LICENSE = "Apache License 2.0"
29
+
30
+ _URL = "https://huggingface.co/datasets/qanastek/MORFITT/resolve/main/data.zip"
31
+
32
+ _CITATION = """\
33
+ (comming soon)
34
+ """
35
+
36
+ class MORFITT(datasets.GeneratorBasedBuilder):
37
+ """MORFITT: A multi-label corpus of French biomedical literature"""
38
+
39
+ VERSION = datasets.Version("1.0.0")
40
+
41
+ def _info(self):
42
+
43
+ features = datasets.Features(
44
+ {
45
+ "id": datasets.Value("string"),
46
+ "abstract": datasets.Value("string"),
47
+ "labels": datasets.Sequence(datasets.features.ClassLabel(
48
+ names=[
49
+ 'chemistry',
50
+ 'etiology',
51
+ 'genetics',
52
+ 'immunology',
53
+ 'microbiology',
54
+ 'parasitology',
55
+ 'pharmacology',
56
+ 'physiology',
57
+ 'psychology',
58
+ 'surgery',
59
+ 'veterinary',
60
+ 'virology',
61
+ ],
62
+ )),
63
+ }
64
+ )
65
+
66
+ return datasets.DatasetInfo(
67
+ description=_DESCRIPTION,
68
+ features=features,
69
+ homepage=_HOMEPAGE,
70
+ license=_LICENSE,
71
+ citation=_CITATION,
72
+ )
73
+
74
+ def _split_generators(self, dl_manager):
75
+ """Returns SplitGenerators."""
76
+
77
+ data_dir = dl_manager.download_and_extract(_URL)
78
+
79
+ return [
80
+ datasets.SplitGenerator(
81
+ name=datasets.Split.TRAIN,
82
+ gen_kwargs={
83
+ "filepath": os.path.join(data_dir, "train.txt"),
84
+ },
85
+ ),
86
+ datasets.SplitGenerator(
87
+ name=datasets.Split.VALIDATION,
88
+ gen_kwargs={
89
+ "filepath": os.path.join(data_dir, "dev.txt"),
90
+ },
91
+ ),
92
+ datasets.SplitGenerator(
93
+ name=datasets.Split.TEST,
94
+ gen_kwargs={
95
+ "filepath": os.path.join(data_dir, "test.txt"),
96
+ },
97
+ ),
98
+ ]
99
+
100
+ def _generate_examples(self, filepath):
101
+
102
+ f_in = open(f"{filepath}","r")
103
+ content = f_in.read()
104
+ f_in.close()
105
+
106
+ for key, line in enumerate(content.split("\n")[1:]):
107
+
108
+ if len(line) <= 0:
109
+ continue
110
+
111
+ identifier, abstract, labels = line.split("\t")
112
+ labels = labels.split("|")
113
+
114
+ yield key, {
115
+ "id": identifier,
116
+ "abstract": abstract,
117
+ "labels": labels,
118
+ }
test_dataset.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+
3
+ dataset = load_dataset("morfitt.py")
4
+
5
+ print("#"*50)
6
+ print(dataset)
7
+ print("#"*50)
8
+ print(dataset["train"])
9
+ print("#"*50)
10
+ print(dataset["train"][0])
11
+ print("#"*50)
12
+
13
+ label_list = dataset["train"].features["labels"].feature.names
14
+ print(label_list)