gabrielaltay
commited on
Commit
•
7f96b41
1
Parent(s):
7cdddf8
Upload constants.py
Browse files- constants.py +86 -0
constants.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import importlib.resources as pkg_resources
|
2 |
+
import json
|
3 |
+
from collections import defaultdict
|
4 |
+
from enum import Enum
|
5 |
+
from types import SimpleNamespace
|
6 |
+
|
7 |
+
from bigbio.utils import resources
|
8 |
+
from bigbio.utils.license import License
|
9 |
+
from bigbio.utils.schemas import (
|
10 |
+
entailment_features,
|
11 |
+
kb_features,
|
12 |
+
pairs_features,
|
13 |
+
qa_features,
|
14 |
+
text2text_features,
|
15 |
+
text_features,
|
16 |
+
)
|
17 |
+
|
18 |
+
BigBioValues = SimpleNamespace(NULL="<BB_NULL_STR>")
|
19 |
+
|
20 |
+
# shamelessly compied from:
|
21 |
+
# https://github.com/huggingface/datasets/blob/master/src/datasets/utils/metadata.py
|
22 |
+
langs_json = pkg_resources.read_text(resources, "languages.json")
|
23 |
+
langs_dict = {k.replace("-", "_").upper(): v for k, v in json.loads(langs_json).items()}
|
24 |
+
Lang = Enum("Lang", langs_dict)
|
25 |
+
|
26 |
+
|
27 |
+
METADATA: dict = {
|
28 |
+
"_LOCAL": bool,
|
29 |
+
"_LANGUAGES": Lang,
|
30 |
+
"_PUBMED": bool,
|
31 |
+
"_LICENSE": License,
|
32 |
+
"_DISPLAYNAME": str,
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
class Tasks(Enum):
|
37 |
+
NAMED_ENTITY_RECOGNITION = "NER"
|
38 |
+
NAMED_ENTITY_DISAMBIGUATION = "NED"
|
39 |
+
EVENT_EXTRACTION = "EE"
|
40 |
+
RELATION_EXTRACTION = "RE"
|
41 |
+
COREFERENCE_RESOLUTION = "COREF"
|
42 |
+
|
43 |
+
QUESTION_ANSWERING = "QA"
|
44 |
+
|
45 |
+
TEXTUAL_ENTAILMENT = "TE"
|
46 |
+
|
47 |
+
SEMANTIC_SIMILARITY = "STS"
|
48 |
+
|
49 |
+
PARAPHRASING = "PARA"
|
50 |
+
TRANSLATION = "TRANSL"
|
51 |
+
SUMMARIZATION = "SUM"
|
52 |
+
|
53 |
+
TEXT_CLASSIFICATION = "TXTCLASS"
|
54 |
+
|
55 |
+
|
56 |
+
TASK_TO_SCHEMA = {
|
57 |
+
Tasks.NAMED_ENTITY_RECOGNITION: "KB",
|
58 |
+
Tasks.NAMED_ENTITY_DISAMBIGUATION: "KB",
|
59 |
+
Tasks.EVENT_EXTRACTION: "KB",
|
60 |
+
Tasks.RELATION_EXTRACTION: "KB",
|
61 |
+
Tasks.COREFERENCE_RESOLUTION: "KB",
|
62 |
+
Tasks.QUESTION_ANSWERING: "QA",
|
63 |
+
Tasks.TEXTUAL_ENTAILMENT: "TE",
|
64 |
+
Tasks.SEMANTIC_SIMILARITY: "PAIRS",
|
65 |
+
Tasks.PARAPHRASING: "T2T",
|
66 |
+
Tasks.TRANSLATION: "T2T",
|
67 |
+
Tasks.SUMMARIZATION: "T2T",
|
68 |
+
Tasks.TEXT_CLASSIFICATION: "TEXT",
|
69 |
+
}
|
70 |
+
|
71 |
+
SCHEMA_TO_TASKS = defaultdict(set)
|
72 |
+
for task, schema in TASK_TO_SCHEMA.items():
|
73 |
+
SCHEMA_TO_TASKS[schema].add(task)
|
74 |
+
SCHEMA_TO_TASKS = dict(SCHEMA_TO_TASKS)
|
75 |
+
|
76 |
+
VALID_TASKS = set(TASK_TO_SCHEMA.keys())
|
77 |
+
VALID_SCHEMAS = set(TASK_TO_SCHEMA.values())
|
78 |
+
|
79 |
+
SCHEMA_TO_FEATURES = {
|
80 |
+
"KB": kb_features,
|
81 |
+
"QA": qa_features,
|
82 |
+
"TE": entailment_features,
|
83 |
+
"T2T": text2text_features,
|
84 |
+
"TEXT": text_features,
|
85 |
+
"PAIRS": pairs_features,
|
86 |
+
}
|