Upload Biobert_json.py
Browse files- Biobert_json.py +119 -0
Biobert_json.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
# Lint as: python3
|
16 |
+
"""Introduction to the Biobert NER Shared Task: Named Entity Recognition"""
|
17 |
+
import datasets
|
18 |
+
import json
|
19 |
+
|
20 |
+
|
21 |
+
logger = datasets.logging.get_logger(__name__)
|
22 |
+
|
23 |
+
_DESCRIPTION = """\
|
24 |
+
Este es un dataset biomédico Biobert para el español con 29 etiquetas"""
|
25 |
+
|
26 |
+
_URL="data56/"
|
27 |
+
_TRAINING_FILE = "train.json"
|
28 |
+
_DEV_FILE = "valid.json"
|
29 |
+
_TEST_FILE = "test.json"
|
30 |
+
|
31 |
+
|
32 |
+
class Biobert_json_Config(datasets.BuilderConfig):
|
33 |
+
|
34 |
+
|
35 |
+
def __init__(self, **kwargs):
|
36 |
+
super(Biobert_json_Config, self).__init__(**kwargs)
|
37 |
+
|
38 |
+
|
39 |
+
class Conll2003(datasets.GeneratorBasedBuilder):
|
40 |
+
"""Conll2003 dataset."""
|
41 |
+
|
42 |
+
BUILDER_CONFIGS = [
|
43 |
+
Biobert_json_Config(name="Biobert_json", version=datasets.Version("1.0.0"), description="Biobert_json dataset"),
|
44 |
+
]
|
45 |
+
|
46 |
+
def _info(self):
|
47 |
+
return datasets.DatasetInfo(
|
48 |
+
description=_DESCRIPTION,
|
49 |
+
features=datasets.Features(
|
50 |
+
{
|
51 |
+
# "id": datasets.Value("string"),
|
52 |
+
"sentencia": datasets.Sequence(datasets.Value("string")),
|
53 |
+
"tag": datasets.Sequence(
|
54 |
+
datasets.features.ClassLabel(
|
55 |
+
names=[
|
56 |
+
"B_CANCER_CONCEPT",
|
57 |
+
"B_CHEMOTHERAPY",
|
58 |
+
"B_DATE",
|
59 |
+
"B_DRUG",
|
60 |
+
"B_FAMILY",
|
61 |
+
"B_FREQ",
|
62 |
+
"B_IMPLICIT_DATE",
|
63 |
+
"B_INTERVAL",
|
64 |
+
"B_METRIC",
|
65 |
+
"B_OCURRENCE_EVENT",
|
66 |
+
"B_QUANTITY",
|
67 |
+
"B_RADIOTHERAPY",
|
68 |
+
"B_SMOKER_STATUS",
|
69 |
+
"B_STAGE",
|
70 |
+
"B_SURGERY",
|
71 |
+
"B_TNM",
|
72 |
+
"I_CANCER_CONCEPT",
|
73 |
+
"I_DATE",
|
74 |
+
"I_DRUG",
|
75 |
+
"I_FAMILY",
|
76 |
+
"I_FREQ",
|
77 |
+
"I_IMPLICIT_DATE",
|
78 |
+
"I_INTERVAL",
|
79 |
+
"I_METRIC",
|
80 |
+
"I_OCURRENCE_EVENT",
|
81 |
+
"I_SMOKER_STATUS",
|
82 |
+
"I_STAGE",
|
83 |
+
"I_SURGERY",
|
84 |
+
"I_TNM",
|
85 |
+
"O",
|
86 |
+
|
87 |
+
]
|
88 |
+
)
|
89 |
+
),
|
90 |
+
}
|
91 |
+
),
|
92 |
+
supervised_keys=None,
|
93 |
+
)
|
94 |
+
|
95 |
+
def _split_generators(self, dl_manager):
|
96 |
+
"""Returns SplitGenerators."""
|
97 |
+
urls_to_download = {
|
98 |
+
"train": f"{_URL}{_TRAINING_FILE}",
|
99 |
+
"val": f"{_URL}{_DEV_FILE}",
|
100 |
+
"test": f"{_URL}{_TEST_FILE}",
|
101 |
+
}
|
102 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
103 |
+
|
104 |
+
return [
|
105 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
106 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["val"]}),
|
107 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
108 |
+
]
|
109 |
+
|
110 |
+
def _generate_examples(self, filepath):
|
111 |
+
logger.info("⏳ Generating examples from = %s", filepath)
|
112 |
+
with open(filepath, encoding="utf-8") as f:
|
113 |
+
guid = 0
|
114 |
+
for line in f:
|
115 |
+
record = json.loads(line)
|
116 |
+
yield guid, record
|
117 |
+
guid += 1
|
118 |
+
|
119 |
+
|