File size: 6,054 Bytes
cfc0d0a dff8822 cfc0d0a dff8822 cfc0d0a dff8822 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
import json
from collections import defaultdict
from enum import Enum
from types import SimpleNamespace
from dataclasses import dataclass
import datasets
from licenses import License
from licenses import Licenses
BigBioValues = SimpleNamespace(NULL="<BB_NULL_STR>")
@dataclass
class BigBioConfig(datasets.BuilderConfig):
"""BuilderConfig for BigBio."""
name: str = None
version: datasets.Version = None
description: str = None
schema: str = None
subset_id: str = None
# shamelessly compied from:
# https://github.com/huggingface/datasets/blob/master/src/datasets/utils/metadata.py
langs_json = json.load(open("languages.json", "r"))
langs_dict = {k.replace("-", "_").upper(): v for k, v in langs_json.items()}
Lang = Enum("Lang", langs_dict)
METADATA: dict = {
"_LOCAL": bool,
"_LANGUAGES": Lang,
"_PUBMED": bool,
"_LICENSE": License,
"_DISPLAYNAME": str,
}
class Tasks(Enum):
NAMED_ENTITY_RECOGNITION = "NER"
NAMED_ENTITY_DISAMBIGUATION = "NED"
EVENT_EXTRACTION = "EE"
RELATION_EXTRACTION = "RE"
COREFERENCE_RESOLUTION = "COREF"
QUESTION_ANSWERING = "QA"
TEXTUAL_ENTAILMENT = "TE"
SEMANTIC_SIMILARITY = "STS"
TEXT_PAIRS_CLASSIFICATION = "TXT2CLASS"
PARAPHRASING = "PARA"
TRANSLATION = "TRANSL"
SUMMARIZATION = "SUM"
TEXT_CLASSIFICATION = "TXTCLASS"
TASK_TO_SCHEMA = {
Tasks.NAMED_ENTITY_RECOGNITION: "KB",
Tasks.NAMED_ENTITY_DISAMBIGUATION: "KB",
Tasks.EVENT_EXTRACTION: "KB",
Tasks.RELATION_EXTRACTION: "KB",
Tasks.COREFERENCE_RESOLUTION: "KB",
Tasks.QUESTION_ANSWERING: "QA",
Tasks.TEXTUAL_ENTAILMENT: "TE",
Tasks.SEMANTIC_SIMILARITY: "PAIRS",
Tasks.TEXT_PAIRS_CLASSIFICATION: "PAIRS",
Tasks.PARAPHRASING: "T2T",
Tasks.TRANSLATION: "T2T",
Tasks.SUMMARIZATION: "T2T",
Tasks.TEXT_CLASSIFICATION: "TEXT",
}
SCHEMA_TO_TASKS = defaultdict(set)
for task, schema in TASK_TO_SCHEMA.items():
SCHEMA_TO_TASKS[schema].add(task)
SCHEMA_TO_TASKS = dict(SCHEMA_TO_TASKS)
VALID_TASKS = set(TASK_TO_SCHEMA.keys())
VALID_SCHEMAS = set(TASK_TO_SCHEMA.values())
entailment_features = datasets.Features(
{
"id": datasets.Value("string"),
"premise": datasets.Value("string"),
"hypothesis": datasets.Value("string"),
"label": datasets.Value("string"),
}
)
pairs_features = datasets.Features(
{
"id": datasets.Value("string"),
"document_id": datasets.Value("string"),
"text_1": datasets.Value("string"),
"text_2": datasets.Value("string"),
"label": datasets.Value("string"),
}
)
qa_features = datasets.Features(
{
"id": datasets.Value("string"),
"question_id": datasets.Value("string"),
"document_id": datasets.Value("string"),
"question": datasets.Value("string"),
"type": datasets.Value("string"),
"choices": [datasets.Value("string")],
"context": datasets.Value("string"),
"answer": datasets.Sequence(datasets.Value("string")),
}
)
text_features = datasets.Features(
{
"id": datasets.Value("string"),
"document_id": datasets.Value("string"),
"text": datasets.Value("string"),
"labels": [datasets.Value("string")],
}
)
text2text_features = datasets.Features(
{
"id": datasets.Value("string"),
"document_id": datasets.Value("string"),
"text_1": datasets.Value("string"),
"text_2": datasets.Value("string"),
"text_1_name": datasets.Value("string"),
"text_2_name": datasets.Value("string"),
}
)
kb_features = datasets.Features(
{
"id": datasets.Value("string"),
"document_id": datasets.Value("string"),
"passages": [
{
"id": datasets.Value("string"),
"type": datasets.Value("string"),
"text": datasets.Sequence(datasets.Value("string")),
"offsets": datasets.Sequence([datasets.Value("int32")]),
}
],
"entities": [
{
"id": datasets.Value("string"),
"type": datasets.Value("string"),
"text": datasets.Sequence(datasets.Value("string")),
"offsets": datasets.Sequence([datasets.Value("int32")]),
"normalized": [
{
"db_name": datasets.Value("string"),
"db_id": datasets.Value("string"),
}
],
}
],
"events": [
{
"id": datasets.Value("string"),
"type": datasets.Value("string"),
# refers to the text_bound_annotation of the trigger
"trigger": {
"text": datasets.Sequence(datasets.Value("string")),
"offsets": datasets.Sequence([datasets.Value("int32")]),
},
"arguments": [
{
"role": datasets.Value("string"),
"ref_id": datasets.Value("string"),
}
],
}
],
"coreferences": [
{
"id": datasets.Value("string"),
"entity_ids": datasets.Sequence(datasets.Value("string")),
}
],
"relations": [
{
"id": datasets.Value("string"),
"type": datasets.Value("string"),
"arg1_id": datasets.Value("string"),
"arg2_id": datasets.Value("string"),
"normalized": [
{
"db_name": datasets.Value("string"),
"db_id": datasets.Value("string"),
}
],
}
],
}
)
SCHEMA_TO_FEATURES = {
"KB": kb_features,
"QA": qa_features,
"TE": entailment_features,
"T2T": text2text_features,
"TEXT": text_features,
"PAIRS": pairs_features,
}
|