Commit ·
cc0c03a
1
Parent(s): fb40aa1
initial commit
Browse files- README.md +40 -0
- bigbiohub.py +153 -0
- mednli.py +201 -0
README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
license: other
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
| 3 |
license: other
|
| 4 |
+
multilinguality: monolingual
|
| 5 |
+
pretty_name: MedNLI
|
| 6 |
+
paperswithcode_id: mednli
|
| 7 |
---
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# Dataset Card for MedNLI
|
| 11 |
+
|
| 12 |
+
## Dataset Description
|
| 13 |
+
|
| 14 |
+
- **Homepage:** https://physionet.org/content/mednli/1.0.0/
|
| 15 |
+
- **Pubmed:** False
|
| 16 |
+
- **Public:** False
|
| 17 |
+
- **Tasks:** Textual Entailment
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
State of the art models using deep neural networks have become very good in learning an accurate
|
| 21 |
+
mapping from inputs to outputs. However, they still lack generalization capabilities in conditions
|
| 22 |
+
that differ from the ones encountered during training. This is even more challenging in specialized,
|
| 23 |
+
and knowledge intensive domains, where training data is limited. To address this gap, we introduce
|
| 24 |
+
MedNLI - a dataset annotated by doctors, performing a natural language inference task (NLI),
|
| 25 |
+
grounded in the medical history of patients. As the source of premise sentences, we used the
|
| 26 |
+
MIMIC-III. More specifically, to minimize the risks to patient privacy, we worked with clinical
|
| 27 |
+
notes corresponding to the deceased patients. The clinicians in our team suggested the Past Medical
|
| 28 |
+
History to be the most informative section of a clinical note, from which useful inferences can be
|
| 29 |
+
drawn about the patient.
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
## Citation Information
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
@misc{https://doi.org/10.13026/c2rs98,
|
| 36 |
+
title = {MedNLI — A Natural Language Inference Dataset For The Clinical Domain},
|
| 37 |
+
author = {Shivade, Chaitanya},
|
| 38 |
+
year = 2017,
|
| 39 |
+
publisher = {physionet.org},
|
| 40 |
+
doi = {10.13026/C2RS98},
|
| 41 |
+
url = {https://physionet.org/content/mednli/}
|
| 42 |
+
}
|
| 43 |
+
```
|
bigbiohub.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
from enum import Enum
|
| 3 |
+
import datasets
|
| 4 |
+
from types import SimpleNamespace
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
BigBioValues = SimpleNamespace(NULL="<BB_NULL_STR>")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@dataclass
|
| 11 |
+
class BigBioConfig(datasets.BuilderConfig):
|
| 12 |
+
"""BuilderConfig for BigBio."""
|
| 13 |
+
|
| 14 |
+
name: str = None
|
| 15 |
+
version: datasets.Version = None
|
| 16 |
+
description: str = None
|
| 17 |
+
schema: str = None
|
| 18 |
+
subset_id: str = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Tasks(Enum):
|
| 22 |
+
NAMED_ENTITY_RECOGNITION = "NER"
|
| 23 |
+
NAMED_ENTITY_DISAMBIGUATION = "NED"
|
| 24 |
+
EVENT_EXTRACTION = "EE"
|
| 25 |
+
RELATION_EXTRACTION = "RE"
|
| 26 |
+
COREFERENCE_RESOLUTION = "COREF"
|
| 27 |
+
QUESTION_ANSWERING = "QA"
|
| 28 |
+
TEXTUAL_ENTAILMENT = "TE"
|
| 29 |
+
SEMANTIC_SIMILARITY = "STS"
|
| 30 |
+
TEXT_PAIRS_CLASSIFICATION = "TXT2CLASS"
|
| 31 |
+
PARAPHRASING = "PARA"
|
| 32 |
+
TRANSLATION = "TRANSL"
|
| 33 |
+
SUMMARIZATION = "SUM"
|
| 34 |
+
TEXT_CLASSIFICATION = "TXTCLASS"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
entailment_features = datasets.Features(
|
| 38 |
+
{
|
| 39 |
+
"id": datasets.Value("string"),
|
| 40 |
+
"premise": datasets.Value("string"),
|
| 41 |
+
"hypothesis": datasets.Value("string"),
|
| 42 |
+
"label": datasets.Value("string"),
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
pairs_features = datasets.Features(
|
| 47 |
+
{
|
| 48 |
+
"id": datasets.Value("string"),
|
| 49 |
+
"document_id": datasets.Value("string"),
|
| 50 |
+
"text_1": datasets.Value("string"),
|
| 51 |
+
"text_2": datasets.Value("string"),
|
| 52 |
+
"label": datasets.Value("string"),
|
| 53 |
+
}
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
qa_features = datasets.Features(
|
| 57 |
+
{
|
| 58 |
+
"id": datasets.Value("string"),
|
| 59 |
+
"question_id": datasets.Value("string"),
|
| 60 |
+
"document_id": datasets.Value("string"),
|
| 61 |
+
"question": datasets.Value("string"),
|
| 62 |
+
"type": datasets.Value("string"),
|
| 63 |
+
"choices": [datasets.Value("string")],
|
| 64 |
+
"context": datasets.Value("string"),
|
| 65 |
+
"answer": datasets.Sequence(datasets.Value("string")),
|
| 66 |
+
}
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
text_features = datasets.Features(
|
| 70 |
+
{
|
| 71 |
+
"id": datasets.Value("string"),
|
| 72 |
+
"document_id": datasets.Value("string"),
|
| 73 |
+
"text": datasets.Value("string"),
|
| 74 |
+
"labels": [datasets.Value("string")],
|
| 75 |
+
}
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
text2text_features = datasets.Features(
|
| 79 |
+
{
|
| 80 |
+
"id": datasets.Value("string"),
|
| 81 |
+
"document_id": datasets.Value("string"),
|
| 82 |
+
"text_1": datasets.Value("string"),
|
| 83 |
+
"text_2": datasets.Value("string"),
|
| 84 |
+
"text_1_name": datasets.Value("string"),
|
| 85 |
+
"text_2_name": datasets.Value("string"),
|
| 86 |
+
}
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
kb_features = datasets.Features(
|
| 90 |
+
{
|
| 91 |
+
"id": datasets.Value("string"),
|
| 92 |
+
"document_id": datasets.Value("string"),
|
| 93 |
+
"passages": [
|
| 94 |
+
{
|
| 95 |
+
"id": datasets.Value("string"),
|
| 96 |
+
"type": datasets.Value("string"),
|
| 97 |
+
"text": datasets.Sequence(datasets.Value("string")),
|
| 98 |
+
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
| 99 |
+
}
|
| 100 |
+
],
|
| 101 |
+
"entities": [
|
| 102 |
+
{
|
| 103 |
+
"id": datasets.Value("string"),
|
| 104 |
+
"type": datasets.Value("string"),
|
| 105 |
+
"text": datasets.Sequence(datasets.Value("string")),
|
| 106 |
+
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
| 107 |
+
"normalized": [
|
| 108 |
+
{
|
| 109 |
+
"db_name": datasets.Value("string"),
|
| 110 |
+
"db_id": datasets.Value("string"),
|
| 111 |
+
}
|
| 112 |
+
],
|
| 113 |
+
}
|
| 114 |
+
],
|
| 115 |
+
"events": [
|
| 116 |
+
{
|
| 117 |
+
"id": datasets.Value("string"),
|
| 118 |
+
"type": datasets.Value("string"),
|
| 119 |
+
# refers to the text_bound_annotation of the trigger
|
| 120 |
+
"trigger": {
|
| 121 |
+
"text": datasets.Sequence(datasets.Value("string")),
|
| 122 |
+
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
| 123 |
+
},
|
| 124 |
+
"arguments": [
|
| 125 |
+
{
|
| 126 |
+
"role": datasets.Value("string"),
|
| 127 |
+
"ref_id": datasets.Value("string"),
|
| 128 |
+
}
|
| 129 |
+
],
|
| 130 |
+
}
|
| 131 |
+
],
|
| 132 |
+
"coreferences": [
|
| 133 |
+
{
|
| 134 |
+
"id": datasets.Value("string"),
|
| 135 |
+
"entity_ids": datasets.Sequence(datasets.Value("string")),
|
| 136 |
+
}
|
| 137 |
+
],
|
| 138 |
+
"relations": [
|
| 139 |
+
{
|
| 140 |
+
"id": datasets.Value("string"),
|
| 141 |
+
"type": datasets.Value("string"),
|
| 142 |
+
"arg1_id": datasets.Value("string"),
|
| 143 |
+
"arg2_id": datasets.Value("string"),
|
| 144 |
+
"normalized": [
|
| 145 |
+
{
|
| 146 |
+
"db_name": datasets.Value("string"),
|
| 147 |
+
"db_id": datasets.Value("string"),
|
| 148 |
+
}
|
| 149 |
+
],
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
}
|
| 153 |
+
)
|
mednli.py
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2022 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 |
+
|
| 16 |
+
"""
|
| 17 |
+
State of the art models using deep neural networks have become very good in learning an accurate
|
| 18 |
+
mapping from inputs to outputs. However, they still lack generalization capabilities in conditions
|
| 19 |
+
that differ from the ones encountered during training. This is even more challenging in specialized,
|
| 20 |
+
and knowledge intensive domains, where training data is limited. To address this gap, we introduce
|
| 21 |
+
MedNLI - a dataset annotated by doctors, performing a natural language inference task (NLI),
|
| 22 |
+
grounded in the medical history of patients. As the source of premise sentences, we used the
|
| 23 |
+
MIMIC-III. More specifically, to minimize the risks to patient privacy, we worked with clinical
|
| 24 |
+
notes corresponding to the deceased patients. The clinicians in our team suggested the Past Medical
|
| 25 |
+
History to be the most informative section of a clinical note, from which useful inferences can be
|
| 26 |
+
drawn about the patient.
|
| 27 |
+
|
| 28 |
+
The files comprising this dataset must be on the users local machine in a single directory that is
|
| 29 |
+
passed to `datasets.load_datset` via the `data_dir` kwarg. This loader script will read the archive
|
| 30 |
+
files directly (i.e. the user should not uncompress, untar or unzip any of the files). For example,
|
| 31 |
+
if `data_dir` is `"mednli"` it should contain the following files:
|
| 32 |
+
|
| 33 |
+
mednli
|
| 34 |
+
├── mednli-a-natural-language-inference-dataset-for-the-clinical-domain-1.0.0.zip
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
import json
|
| 38 |
+
import os
|
| 39 |
+
from typing import Dict, List, Tuple
|
| 40 |
+
|
| 41 |
+
import datasets
|
| 42 |
+
|
| 43 |
+
from .bigbiohub import entailment_features
|
| 44 |
+
from .bigbiohub import BigBioConfig
|
| 45 |
+
from .bigbiohub import Tasks
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
_LANGUAGES = ["English"]
|
| 49 |
+
_PUBMED = False
|
| 50 |
+
_LOCAL = True
|
| 51 |
+
_CITATION = """\
|
| 52 |
+
@misc{https://doi.org/10.13026/c2rs98,
|
| 53 |
+
title = {MedNLI — A Natural Language Inference Dataset For The Clinical Domain},
|
| 54 |
+
author = {Shivade, Chaitanya},
|
| 55 |
+
year = 2017,
|
| 56 |
+
publisher = {physionet.org},
|
| 57 |
+
doi = {10.13026/C2RS98},
|
| 58 |
+
url = {https://physionet.org/content/mednli/}
|
| 59 |
+
}
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
_DATASETNAME = "mednli"
|
| 64 |
+
_DISPLAYNAME = "MedNLI"
|
| 65 |
+
|
| 66 |
+
_DESCRIPTION = """\
|
| 67 |
+
State of the art models using deep neural networks have become very good in learning an accurate
|
| 68 |
+
mapping from inputs to outputs. However, they still lack generalization capabilities in conditions
|
| 69 |
+
that differ from the ones encountered during training. This is even more challenging in specialized,
|
| 70 |
+
and knowledge intensive domains, where training data is limited. To address this gap, we introduce
|
| 71 |
+
MedNLI - a dataset annotated by doctors, performing a natural language inference task (NLI),
|
| 72 |
+
grounded in the medical history of patients. As the source of premise sentences, we used the
|
| 73 |
+
MIMIC-III. More specifically, to minimize the risks to patient privacy, we worked with clinical
|
| 74 |
+
notes corresponding to the deceased patients. The clinicians in our team suggested the Past Medical
|
| 75 |
+
History to be the most informative section of a clinical note, from which useful inferences can be
|
| 76 |
+
drawn about the patient.
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
_HOMEPAGE = "https://physionet.org/content/mednli/1.0.0/"
|
| 81 |
+
|
| 82 |
+
_LICENSE = "PHYSIONET_LICENSE_1p5"
|
| 83 |
+
|
| 84 |
+
_URLS = {}
|
| 85 |
+
|
| 86 |
+
_SUPPORTED_TASKS = [Tasks.TEXTUAL_ENTAILMENT]
|
| 87 |
+
|
| 88 |
+
_SOURCE_VERSION = "1.0.0"
|
| 89 |
+
_BIGBIO_VERSION = "1.0.0"
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class MedNLIDataset(datasets.GeneratorBasedBuilder):
|
| 93 |
+
"""MedNLI"""
|
| 94 |
+
|
| 95 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 96 |
+
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
| 97 |
+
|
| 98 |
+
BUILDER_CONFIGS = [
|
| 99 |
+
BigBioConfig(
|
| 100 |
+
name="mednli_source",
|
| 101 |
+
version=SOURCE_VERSION,
|
| 102 |
+
description="MedNLI source schema",
|
| 103 |
+
schema="source",
|
| 104 |
+
subset_id="mednli",
|
| 105 |
+
),
|
| 106 |
+
BigBioConfig(
|
| 107 |
+
name="mednli_bigbio_te",
|
| 108 |
+
version=BIGBIO_VERSION,
|
| 109 |
+
description="MedNLI BigBio schema",
|
| 110 |
+
schema="bigbio_te",
|
| 111 |
+
subset_id="mednli",
|
| 112 |
+
),
|
| 113 |
+
]
|
| 114 |
+
|
| 115 |
+
DEFAULT_CONFIG_NAME = "mednli_source"
|
| 116 |
+
|
| 117 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 118 |
+
|
| 119 |
+
if self.config.schema == "source":
|
| 120 |
+
features = datasets.Features(
|
| 121 |
+
{
|
| 122 |
+
"pairID": datasets.Value("string"),
|
| 123 |
+
"gold_label": datasets.Value("string"),
|
| 124 |
+
"sentence1": datasets.Value("string"),
|
| 125 |
+
"sentence2": datasets.Value("string"),
|
| 126 |
+
"sentence1_parse": datasets.Value("string"),
|
| 127 |
+
"sentence2_parse": datasets.Value("string"),
|
| 128 |
+
"sentence1_binary_parse": datasets.Value("string"),
|
| 129 |
+
"sentence2_binary_parse": datasets.Value("string"),
|
| 130 |
+
}
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
elif self.config.schema == "bigbio_te":
|
| 134 |
+
features = entailment_features
|
| 135 |
+
|
| 136 |
+
return datasets.DatasetInfo(
|
| 137 |
+
description=_DESCRIPTION,
|
| 138 |
+
features=features,
|
| 139 |
+
homepage=_HOMEPAGE,
|
| 140 |
+
license=str(_LICENSE),
|
| 141 |
+
citation=_CITATION,
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
| 145 |
+
if self.config.data_dir is None:
|
| 146 |
+
raise ValueError(
|
| 147 |
+
"This is a local dataset. Please pass the data_dir kwarg to load_dataset."
|
| 148 |
+
)
|
| 149 |
+
else:
|
| 150 |
+
extract_dir = dl_manager.extract(
|
| 151 |
+
os.path.join(
|
| 152 |
+
self.config.data_dir,
|
| 153 |
+
"mednli-a-natural-language-inference-dataset-for-the-clinical-domain-1.0.0.zip",
|
| 154 |
+
)
|
| 155 |
+
)
|
| 156 |
+
data_dir = os.path.join(
|
| 157 |
+
extract_dir,
|
| 158 |
+
"mednli-a-natural-language-inference-dataset-for-the-clinical-domain-1.0.0",
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
return [
|
| 162 |
+
datasets.SplitGenerator(
|
| 163 |
+
name=datasets.Split.TRAIN,
|
| 164 |
+
gen_kwargs={
|
| 165 |
+
"filepath": os.path.join(data_dir, "mli_train_v1.jsonl"),
|
| 166 |
+
"split": "train",
|
| 167 |
+
},
|
| 168 |
+
),
|
| 169 |
+
datasets.SplitGenerator(
|
| 170 |
+
name=datasets.Split.TEST,
|
| 171 |
+
gen_kwargs={
|
| 172 |
+
"filepath": os.path.join(data_dir, "mli_test_v1.jsonl"),
|
| 173 |
+
"split": "test",
|
| 174 |
+
},
|
| 175 |
+
),
|
| 176 |
+
datasets.SplitGenerator(
|
| 177 |
+
name=datasets.Split.VALIDATION,
|
| 178 |
+
gen_kwargs={
|
| 179 |
+
"filepath": os.path.join(data_dir, "mli_dev_v1.jsonl"),
|
| 180 |
+
"split": "dev",
|
| 181 |
+
},
|
| 182 |
+
),
|
| 183 |
+
]
|
| 184 |
+
|
| 185 |
+
def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
|
| 186 |
+
with open(filepath, "r") as f:
|
| 187 |
+
if self.config.schema == "source":
|
| 188 |
+
for line in f:
|
| 189 |
+
json_line = json.loads(line)
|
| 190 |
+
yield json_line["pairID"], json_line
|
| 191 |
+
|
| 192 |
+
elif self.config.schema == "bigbio_te":
|
| 193 |
+
for line in f:
|
| 194 |
+
json_line = json.loads(line)
|
| 195 |
+
entailment_example = {
|
| 196 |
+
"id": json_line["pairID"],
|
| 197 |
+
"premise": json_line["sentence1"],
|
| 198 |
+
"hypothesis": json_line["sentence2"],
|
| 199 |
+
"label": json_line["gold_label"],
|
| 200 |
+
}
|
| 201 |
+
yield json_line["pairID"], entailment_example
|