gabrielaltay
commited on
Commit
·
0098e9d
1
Parent(s):
1198b72
https://github.com/bigscience-workshop/biomedical/pull/736/files (#1)
Browse files- https://github.com/bigscience-workshop/biomedical/pull/736/files (cf67932212127f2c698f18d7deb27afee16814e9)
- distemist.py +58 -51
distemist.py
CHANGED
@@ -23,20 +23,19 @@ from .bigbiohub import kb_features
|
|
23 |
from .bigbiohub import BigBioConfig
|
24 |
from .bigbiohub import Tasks
|
25 |
|
26 |
-
_LANGUAGES = ['
|
27 |
_PUBMED = False
|
28 |
_LOCAL = False
|
29 |
_CITATION = """\
|
30 |
-
@
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
url = {https://doi.org/10.5281/zenodo.6458455}
|
40 |
}
|
41 |
"""
|
42 |
|
@@ -48,17 +47,17 @@ The DisTEMIST corpus is a collection of 1000 clinical cases with disease annotat
|
|
48 |
All documents are released in the context of the BioASQ DisTEMIST track for CLEF 2022.
|
49 |
"""
|
50 |
|
51 |
-
_HOMEPAGE = "https://zenodo.org/record/
|
52 |
|
53 |
_LICENSE = 'Creative Commons Attribution 4.0 International'
|
54 |
|
55 |
_URLS = {
|
56 |
-
_DATASETNAME: "https://zenodo.org/record/
|
57 |
}
|
58 |
|
59 |
-
_SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION]
|
60 |
|
61 |
-
_SOURCE_VERSION = "
|
62 |
_BIGBIO_VERSION = "1.0.0"
|
63 |
|
64 |
|
@@ -73,22 +72,36 @@ class DistemistDataset(datasets.GeneratorBasedBuilder):
|
|
73 |
|
74 |
BUILDER_CONFIGS = [
|
75 |
BigBioConfig(
|
76 |
-
name="
|
77 |
version=SOURCE_VERSION,
|
78 |
-
description="DisTEMIST source schema",
|
79 |
schema="source",
|
80 |
-
subset_id="
|
81 |
),
|
82 |
BigBioConfig(
|
83 |
-
name="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
version=BIGBIO_VERSION,
|
85 |
-
description="DisTEMIST BigBio schema",
|
86 |
schema="bigbio_kb",
|
87 |
-
subset_id="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
),
|
89 |
]
|
90 |
|
91 |
-
DEFAULT_CONFIG_NAME = "
|
92 |
|
93 |
def _info(self) -> datasets.DatasetInfo:
|
94 |
|
@@ -111,12 +124,8 @@ class DistemistDataset(datasets.GeneratorBasedBuilder):
|
|
111 |
"type": datasets.Value("string"),
|
112 |
"text": datasets.Sequence(datasets.Value("string")),
|
113 |
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
114 |
-
"concept_codes": datasets.Sequence(
|
115 |
-
|
116 |
-
),
|
117 |
-
"semantic_relations": datasets.Sequence(
|
118 |
-
datasets.Value("string")
|
119 |
-
),
|
120 |
}
|
121 |
],
|
122 |
}
|
@@ -136,33 +145,33 @@ class DistemistDataset(datasets.GeneratorBasedBuilder):
|
|
136 |
"""Returns SplitGenerators."""
|
137 |
urls = _URLS[_DATASETNAME]
|
138 |
data_dir = dl_manager.download_and_extract(urls)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
return [
|
140 |
datasets.SplitGenerator(
|
141 |
name=datasets.Split.TRAIN,
|
142 |
gen_kwargs={
|
143 |
-
"
|
144 |
-
/ "
|
145 |
-
"linking_mapping_file_path": Path(data_dir)
|
146 |
-
/ "training/subtrack2_linking/distemist_subtrack1_training1_linking.tsv",
|
147 |
-
"text_files_dir": Path(data_dir) / "training/text_files",
|
148 |
},
|
149 |
),
|
150 |
]
|
151 |
|
152 |
def _generate_examples(
|
153 |
self,
|
154 |
-
|
155 |
-
linking_mapping_file_path: Path,
|
156 |
text_files_dir: Path,
|
157 |
) -> Tuple[int, Dict]:
|
158 |
"""Yields examples as (key, example) tuples."""
|
159 |
-
entities_mapping = pd.read_csv(entities_mapping_file_path, sep="\t")
|
160 |
-
linking_mapping = pd.read_csv(linking_mapping_file_path, sep="\t")
|
161 |
-
|
162 |
-
entity_file_names = set(entities_mapping["filename"])
|
163 |
-
linking_file_names = set(linking_mapping["filename"])
|
164 |
|
165 |
-
|
|
|
166 |
|
167 |
for uid, filename in enumerate(entity_file_names):
|
168 |
text_file = text_files_dir / f"{filename}.txt"
|
@@ -170,14 +179,7 @@ class DistemistDataset(datasets.GeneratorBasedBuilder):
|
|
170 |
doc_text = text_file.read_text()
|
171 |
# doc_text = doc_text.replace("\n", "")
|
172 |
|
173 |
-
|
174 |
-
entities_df: pd.DataFrame = linking_mapping[
|
175 |
-
linking_mapping["filename"] == filename
|
176 |
-
]
|
177 |
-
else:
|
178 |
-
entities_df: pd.DataFrame = entities_mapping[
|
179 |
-
entities_mapping["filename"] == filename
|
180 |
-
]
|
181 |
|
182 |
example = {
|
183 |
"id": f"{uid}",
|
@@ -207,12 +209,17 @@ class DistemistDataset(datasets.GeneratorBasedBuilder):
|
|
207 |
if self.config.schema == "source":
|
208 |
entity["concept_codes"] = []
|
209 |
entity["semantic_relations"] = []
|
210 |
-
if
|
211 |
entity["concept_codes"] = row.code.split("+")
|
212 |
entity["semantic_relations"] = row.semantic_rel.split("+")
|
213 |
|
214 |
elif self.config.schema == "bigbio_kb":
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
entities.append(entity)
|
218 |
|
|
|
23 |
from .bigbiohub import BigBioConfig
|
24 |
from .bigbiohub import Tasks
|
25 |
|
26 |
+
_LANGUAGES = ['Spanish']
|
27 |
_PUBMED = False
|
28 |
_LOCAL = False
|
29 |
_CITATION = """\
|
30 |
+
@article{miranda2022overview,
|
31 |
+
title={Overview of DisTEMIST at BioASQ: Automatic detection and normalization of diseases
|
32 |
+
from clinical texts: results, methods, evaluation and multilingual resources},
|
33 |
+
author={Miranda-Escalada, Antonio and Gascó, Luis and Lima-López, Salvador and Farré-Maduell,
|
34 |
+
Eulàlia and Estrada, Darryl and Nentidis, Anastasios and Krithara, Anastasia and Katsimpras,
|
35 |
+
Georgios and Paliouras, Georgios and Krallinger, Martin},
|
36 |
+
booktitle={Working Notes of Conference and Labs of the Evaluation (CLEF) Forum.
|
37 |
+
CEUR Workshop Proceedings},
|
38 |
+
year={2022}
|
|
|
39 |
}
|
40 |
"""
|
41 |
|
|
|
47 |
All documents are released in the context of the BioASQ DisTEMIST track for CLEF 2022.
|
48 |
"""
|
49 |
|
50 |
+
_HOMEPAGE = "https://zenodo.org/record/6671292"
|
51 |
|
52 |
_LICENSE = 'Creative Commons Attribution 4.0 International'
|
53 |
|
54 |
_URLS = {
|
55 |
+
_DATASETNAME: "https://zenodo.org/record/6671292/files/distemist.zip?download=1",
|
56 |
}
|
57 |
|
58 |
+
_SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION, Tasks.NAMED_ENTITY_DISAMBIGUATION]
|
59 |
|
60 |
+
_SOURCE_VERSION = "5.1.0"
|
61 |
_BIGBIO_VERSION = "1.0.0"
|
62 |
|
63 |
|
|
|
72 |
|
73 |
BUILDER_CONFIGS = [
|
74 |
BigBioConfig(
|
75 |
+
name="distemist_entities_source",
|
76 |
version=SOURCE_VERSION,
|
77 |
+
description="DisTEMIST (subtrack 1: entities) source schema",
|
78 |
schema="source",
|
79 |
+
subset_id="distemist_entities",
|
80 |
),
|
81 |
BigBioConfig(
|
82 |
+
name="distemist_linking_source",
|
83 |
+
version=SOURCE_VERSION,
|
84 |
+
description="DisTEMIST (subtrack 2: linking) source schema",
|
85 |
+
schema="source",
|
86 |
+
subset_id="distemist_linking",
|
87 |
+
),
|
88 |
+
BigBioConfig(
|
89 |
+
name="distemist_entities_bigbio_kb",
|
90 |
version=BIGBIO_VERSION,
|
91 |
+
description="DisTEMIST (subtrack 1: entities) BigBio schema",
|
92 |
schema="bigbio_kb",
|
93 |
+
subset_id="distemist_entities",
|
94 |
+
),
|
95 |
+
BigBioConfig(
|
96 |
+
name="distemist_linking_bigbio_kb",
|
97 |
+
version=BIGBIO_VERSION,
|
98 |
+
description="DisTEMIST (subtrack 2: linking) BigBio schema",
|
99 |
+
schema="bigbio_kb",
|
100 |
+
subset_id="distemist_linking",
|
101 |
),
|
102 |
]
|
103 |
|
104 |
+
DEFAULT_CONFIG_NAME = "distemist_entities_source"
|
105 |
|
106 |
def _info(self) -> datasets.DatasetInfo:
|
107 |
|
|
|
124 |
"type": datasets.Value("string"),
|
125 |
"text": datasets.Sequence(datasets.Value("string")),
|
126 |
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
127 |
+
"concept_codes": datasets.Sequence(datasets.Value("string")),
|
128 |
+
"semantic_relations": datasets.Sequence(datasets.Value("string")),
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
],
|
131 |
}
|
|
|
145 |
"""Returns SplitGenerators."""
|
146 |
urls = _URLS[_DATASETNAME]
|
147 |
data_dir = dl_manager.download_and_extract(urls)
|
148 |
+
base_bath = Path(data_dir) / "distemist" / "training"
|
149 |
+
if self.config.subset_id == "distemist_entities":
|
150 |
+
entity_mapping_files = [base_bath / "subtrack1_entities" / "distemist_subtrack1_training_mentions.tsv"]
|
151 |
+
else:
|
152 |
+
entity_mapping_files = [
|
153 |
+
base_bath / "subtrack2_linking" / "distemist_subtrack2_training1_linking.tsv",
|
154 |
+
base_bath / "subtrack2_linking" / "distemist_subtrack2_training2_linking.tsv",
|
155 |
+
]
|
156 |
return [
|
157 |
datasets.SplitGenerator(
|
158 |
name=datasets.Split.TRAIN,
|
159 |
gen_kwargs={
|
160 |
+
"entity_mapping_files": entity_mapping_files,
|
161 |
+
"text_files_dir": base_bath / "text_files",
|
|
|
|
|
|
|
162 |
},
|
163 |
),
|
164 |
]
|
165 |
|
166 |
def _generate_examples(
|
167 |
self,
|
168 |
+
entity_mapping_files: List[Path],
|
|
|
169 |
text_files_dir: Path,
|
170 |
) -> Tuple[int, Dict]:
|
171 |
"""Yields examples as (key, example) tuples."""
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
+
entities_mapping = pd.concat([pd.read_csv(file, sep="\t") for file in entity_mapping_files])
|
174 |
+
entity_file_names = entities_mapping["filename"].unique()
|
175 |
|
176 |
for uid, filename in enumerate(entity_file_names):
|
177 |
text_file = text_files_dir / f"{filename}.txt"
|
|
|
179 |
doc_text = text_file.read_text()
|
180 |
# doc_text = doc_text.replace("\n", "")
|
181 |
|
182 |
+
entities_df: pd.DataFrame = entities_mapping[entities_mapping["filename"] == filename]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
example = {
|
185 |
"id": f"{uid}",
|
|
|
209 |
if self.config.schema == "source":
|
210 |
entity["concept_codes"] = []
|
211 |
entity["semantic_relations"] = []
|
212 |
+
if self.config.subset_id == "distemist_linking":
|
213 |
entity["concept_codes"] = row.code.split("+")
|
214 |
entity["semantic_relations"] = row.semantic_rel.split("+")
|
215 |
|
216 |
elif self.config.schema == "bigbio_kb":
|
217 |
+
if self.config.subset_id == "distemist_linking":
|
218 |
+
entity["normalized"] = [
|
219 |
+
{"db_id": code, "db_name": "SNOMED_CT"} for code in row.code.split("+")
|
220 |
+
]
|
221 |
+
else:
|
222 |
+
entity["normalized"] = []
|
223 |
|
224 |
entities.append(entity)
|
225 |
|