Matías Rojas commited on
Commit
70d460f
1 Parent(s): 0822f12

files added

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
data/.DS_Store ADDED
Binary file (6.15 kB). View file
 
data/Medication_dev.conll ADDED
The diff for this file is too large to render. See raw diff
 
data/Medication_test.conll ADDED
The diff for this file is too large to render. See raw diff
 
data/Medication_train.conll ADDED
The diff for this file is too large to render. See raw diff
 
medication.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+
4
+ logger = datasets.logging.get_logger(__name__)
5
+
6
+
7
+ _CITATION = """\
8
+
9
+ """
10
+
11
+ _DESCRIPTION = """\
12
+
13
+
14
+ """
15
+
16
+ _URL = "https://huggingface.co/datasets/mrojas/medication/resolve/main/data/"
17
+ _TRAINING_FILE = "Medication_train.conll"
18
+ _DEV_FILE = "Medication_dev.conll"
19
+ _TEST_FILE = "Medication_test.conll"
20
+
21
+
22
+ class MedicationConfig(datasets.BuilderConfig):
23
+ """BuilderConfig for Medication"""
24
+
25
+ def __init__(self, **kwargs):
26
+ """BuilderConfig for Medication.
27
+ Args:
28
+ **kwargs: keyword arguments forwarded to super.
29
+ """
30
+ super(MedicationConfig, self).__init__(**kwargs)
31
+
32
+
33
+ class Medication(datasets.GeneratorBasedBuilder):
34
+ """Medication dataset."""
35
+
36
+ BUILDER_CONFIGS = [
37
+ MedicationConfig(name="medication", version=datasets.Version("1.0.0"), description="Medication dataset"),
38
+ ]
39
+
40
+ def _info(self):
41
+ return datasets.DatasetInfo(
42
+ description=_DESCRIPTION,
43
+ features=datasets.Features(
44
+ {
45
+ "tokens": datasets.Sequence(datasets.Value("string")),
46
+ "ner_tags": datasets.Sequence(
47
+ datasets.features.ClassLabel(
48
+ names=[
49
+ "O",
50
+ "B-Medication",
51
+ "I-Medication",
52
+ ]
53
+ )
54
+ ),
55
+ }
56
+ ),
57
+ supervised_keys=None,
58
+ homepage="",
59
+ citation=_CITATION,
60
+ )
61
+
62
+ def _split_generators(self, dl_manager):
63
+ """Returns SplitGenerators."""
64
+ urls_to_download = {
65
+ "train": f"{_URL}{_TRAINING_FILE}",
66
+ "dev": f"{_URL}{_DEV_FILE}",
67
+ "test": f"{_URL}{_TEST_FILE}",
68
+ }
69
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
70
+
71
+ return [
72
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
73
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
74
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
75
+ ]
76
+
77
+ def _generate_examples(self, filepath):
78
+ logger.info("⏳ Generating examples from = %s", filepath)
79
+ with open(filepath, encoding="utf-8") as f:
80
+ id_ = 0
81
+ tokens = []
82
+ ner_tags = []
83
+ for line in f:
84
+ if line == "" or line == "\n":
85
+ if tokens:
86
+ yield id_, {
87
+ "tokens": tokens,
88
+ "ner_tags": ner_tags,
89
+ }
90
+ id_ += 1
91
+ tokens = []
92
+ ner_tags = []
93
+ else:
94
+ # conll2003 tokens are space separated
95
+ splits = line.split(" ")
96
+ tokens.append(splits[0])
97
+ ner_tags.append(splits[1].rstrip())
98
+ # last example
99
+ yield id_, {
100
+ "tokens": tokens,
101
+ "ner_tags": ner_tags,
102
+ }