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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
_CITATION = """\
|
| 10 |
+
@inproceedings{grouin-etal-2021-classification,
|
| 11 |
+
title = "Classification de cas cliniques et {\'e}valuation automatique de r{\'e}ponses d{'}{\'e}tudiants : pr{\'e}sentation de la campagne {DEFT} 2021 (Clinical cases classification and automatic evaluation of student answers : Presentation of the {DEFT} 2021 Challenge)",
|
| 12 |
+
author = "Grouin, Cyril and
|
| 13 |
+
Grabar, Natalia and
|
| 14 |
+
Illouz, Gabriel",
|
| 15 |
+
booktitle = "Actes de la 28e Conf{\'e}rence sur le Traitement Automatique des Langues Naturelles. Atelier D{\'E}fi Fouille de Textes (DEFT)",
|
| 16 |
+
month = "6",
|
| 17 |
+
year = "2021",
|
| 18 |
+
address = "Lille, France",
|
| 19 |
+
publisher = "ATALA",
|
| 20 |
+
url = "https://aclanthology.org/2021.jeptalnrecital-deft.1",
|
| 21 |
+
pages = "1--13",
|
| 22 |
+
abstract = "Le d{\'e}fi fouille de textes (DEFT) est une campagne d{'}{\'e}valuation annuelle francophone. Nous pr{\'e}sentons les corpus et baselines {\'e}labor{\'e}es pour trois t{\^a}ches : (i) identifier le profil clinique de patients d{\'e}crits dans des cas cliniques, (ii) {\'e}valuer automatiquement les r{\'e}ponses d{'}{\'e}tudiants sur des questionnaires en ligne (Moodle) {\`a} partir de la correction de l{'}enseignant, et (iii) poursuivre une {\'e}valuation de r{\'e}ponses d{'}{\'e}tudiants {\`a} partir de r{\'e}ponses d{\'e}j{\`a} {\'e}valu{\'e}es par l{'}enseignant. Les r{\'e}sultats varient de 0,394 {\`a} 0,814 de F-mesure sur la premi{\`e}re t{\^a}che (7 {\'e}quipes), de 0,448 {\`a} 0,682 de pr{\'e}cision sur la deuxi{\`e}me (3 {\'e}quipes), et de 0,133 {\`a} 0,510 de pr{\'e}cision sur la derni{\`e}re (3 {\'e}quipes).",
|
| 23 |
+
language = "French",
|
| 24 |
+
}
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
_DESCRIPTION = """\
|
| 28 |
+
ddd
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
_HOMEPAGE = "ddd"
|
| 32 |
+
|
| 33 |
+
_LICENSE = "unknown"
|
| 34 |
+
|
| 35 |
+
_SPECIALITIES = ['immunitaire', 'endocriniennes', 'blessures', 'chimiques', 'etatsosy', 'nutritionnelles', 'infections', 'virales', 'parasitaires', 'tumeur', 'osteomusculaires', 'stomatognathique', 'digestif', 'respiratoire', 'ORL', 'nerveux', 'oeil', 'homme', 'femme', 'cardiovasculaires', 'hemopathies', 'genetique', 'peau']
|
| 36 |
+
|
| 37 |
+
class DEFT2021(datasets.GeneratorBasedBuilder):
|
| 38 |
+
|
| 39 |
+
DEFAULT_CONFIG_NAME = "source"
|
| 40 |
+
|
| 41 |
+
BUILDER_CONFIGS = [
|
| 42 |
+
datasets.BuilderConfig(name="source", version="1.0.0", description="DEFT 2021 corpora"),
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
def _info(self):
|
| 46 |
+
|
| 47 |
+
features = datasets.Features(
|
| 48 |
+
{
|
| 49 |
+
"id": datasets.Value("string"),
|
| 50 |
+
"document_id": datasets.Value("string"),
|
| 51 |
+
"text": datasets.Value("string"),
|
| 52 |
+
"specialities": datasets.Sequence(
|
| 53 |
+
datasets.features.ClassLabel(names=_SPECIALITIES),
|
| 54 |
+
),
|
| 55 |
+
"specialities_one_hot": datasets.Sequence(
|
| 56 |
+
datasets.Value("float"),
|
| 57 |
+
),
|
| 58 |
+
}
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
return datasets.DatasetInfo(
|
| 62 |
+
description=_DESCRIPTION,
|
| 63 |
+
features=features,
|
| 64 |
+
supervised_keys=None,
|
| 65 |
+
homepage=_HOMEPAGE,
|
| 66 |
+
license=str(_LICENSE),
|
| 67 |
+
citation=_CITATION,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
def _split_generators(self, dl_manager):
|
| 71 |
+
|
| 72 |
+
if self.config.data_dir is None:
|
| 73 |
+
raise ValueError("This is a local dataset. Please pass the data_dir kwarg to load_dataset.")
|
| 74 |
+
|
| 75 |
+
else:
|
| 76 |
+
data_dir = self.config.data_dir
|
| 77 |
+
|
| 78 |
+
return [
|
| 79 |
+
datasets.SplitGenerator(
|
| 80 |
+
name=datasets.Split.TRAIN,
|
| 81 |
+
gen_kwargs={
|
| 82 |
+
"data_dir": data_dir,
|
| 83 |
+
"split": "train",
|
| 84 |
+
},
|
| 85 |
+
),
|
| 86 |
+
datasets.SplitGenerator(
|
| 87 |
+
name=datasets.Split.VALIDATION,
|
| 88 |
+
gen_kwargs={
|
| 89 |
+
"data_dir": data_dir,
|
| 90 |
+
"split": "validation",
|
| 91 |
+
},
|
| 92 |
+
),
|
| 93 |
+
datasets.SplitGenerator(
|
| 94 |
+
name=datasets.Split.TEST,
|
| 95 |
+
gen_kwargs={
|
| 96 |
+
"data_dir": data_dir,
|
| 97 |
+
"split": "test",
|
| 98 |
+
},
|
| 99 |
+
),
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
def _generate_examples(self, data_dir, split):
|
| 103 |
+
|
| 104 |
+
all_res = {}
|
| 105 |
+
|
| 106 |
+
key = 0
|
| 107 |
+
|
| 108 |
+
if split == 'train' or split == 'validation':
|
| 109 |
+
split_eval = 'train'
|
| 110 |
+
else:
|
| 111 |
+
split_eval = 'test'
|
| 112 |
+
|
| 113 |
+
path_labels = Path(data_dir) / 'evaluations' / f"ref-{split_eval}-deft2021.txt"
|
| 114 |
+
|
| 115 |
+
with open(os.path.join(data_dir, 'distribution-corpus.txt')) as f_dist:
|
| 116 |
+
|
| 117 |
+
doc_specialities_ = {}
|
| 118 |
+
with open(path_labels) as f_spec:
|
| 119 |
+
doc_specialities = [line.strip() for line in f_spec.readlines()]
|
| 120 |
+
for raw in doc_specialities:
|
| 121 |
+
raw_split = raw.split('\t')
|
| 122 |
+
if len(raw_split) == 3 and raw_split[0] in doc_specialities_:
|
| 123 |
+
doc_specialities_[raw_split[0]].append(raw_split[1])
|
| 124 |
+
elif len(raw_split) == 3 and raw_split[0] not in doc_specialities_:
|
| 125 |
+
doc_specialities_[raw_split[0]] = [raw_split[1]]
|
| 126 |
+
|
| 127 |
+
ann_path = Path(data_dir) / "DEFT-cas-cliniques"
|
| 128 |
+
|
| 129 |
+
for guid, txt_file in enumerate(sorted(ann_path.glob("*.txt"))):
|
| 130 |
+
|
| 131 |
+
ann_file = txt_file.with_suffix("").name.split('.')[0]+'.ann'
|
| 132 |
+
|
| 133 |
+
if ann_file in doc_specialities_:
|
| 134 |
+
|
| 135 |
+
res = {}
|
| 136 |
+
res['document_id'] = txt_file.with_suffix("").name
|
| 137 |
+
with txt_file.open() as f:
|
| 138 |
+
res["text"] = f.read()
|
| 139 |
+
|
| 140 |
+
specialities = doc_specialities_[ann_file]
|
| 141 |
+
|
| 142 |
+
# Empty one hot vector
|
| 143 |
+
one_hot = [0.0 for i in _SPECIALITIES]
|
| 144 |
+
|
| 145 |
+
# Fill up the one hot vector
|
| 146 |
+
for s in specialities:
|
| 147 |
+
one_hot[_SPECIALITIES.index(s)] = 1.0
|
| 148 |
+
|
| 149 |
+
all_res[res['document_id']] = {
|
| 150 |
+
"id": str(key),
|
| 151 |
+
"document_id": res['document_id'],
|
| 152 |
+
"text": res["text"],
|
| 153 |
+
"specialities": specialities,
|
| 154 |
+
"specialities_one_hot": one_hot,
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
key += 1
|
| 158 |
+
|
| 159 |
+
distribution = [line.strip() for line in f_dist.readlines()]
|
| 160 |
+
|
| 161 |
+
random.seed(4)
|
| 162 |
+
train = [raw.split('\t')[0] for raw in distribution if len(raw.split('\t')) == 4 and raw.split('\t')[3] == 'train 2021']
|
| 163 |
+
random.shuffle(train)
|
| 164 |
+
random.shuffle(train)
|
| 165 |
+
random.shuffle(train)
|
| 166 |
+
train, validation = np.split(train, [int(len(train)*0.7096)])
|
| 167 |
+
|
| 168 |
+
test = [raw.split('\t')[0] for raw in distribution if len(raw.split('\t')) == 4 and raw.split('\t')[3] == 'test 2021']
|
| 169 |
+
|
| 170 |
+
if split == "train":
|
| 171 |
+
allowed_ids = list(train)
|
| 172 |
+
elif split == "test":
|
| 173 |
+
allowed_ids = list(test)
|
| 174 |
+
elif split == "validation":
|
| 175 |
+
allowed_ids = list(validation)
|
| 176 |
+
|
| 177 |
+
for r in all_res.values():
|
| 178 |
+
if r["document_id"]+'.txt' in allowed_ids:
|
| 179 |
+
yield r["id"], r
|