Update QUAERO.py
Browse files
QUAERO.py
CHANGED
@@ -55,6 +55,39 @@ All questions regarding the task or data should be addressed to aurelie.neveol@l
|
|
55 |
|
56 |
_LABELS_BASE = ['DISO', 'DEVI', 'CHEM', 'GEOG', 'OBJC', 'PHEN', 'PHYS', 'LIVB', 'PROC', 'ANAT']
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
class QUAERO(datasets.GeneratorBasedBuilder):
|
59 |
"""QUAERO dataset."""
|
60 |
|
@@ -83,6 +116,11 @@ class QUAERO(datasets.GeneratorBasedBuilder):
|
|
83 |
names = ['O', 'B-LIVB', 'I-LIVB', 'B-PROC', 'I-PROC', 'B-ANAT', 'I-ANAT', 'B-DEVI', 'I-DEVI', 'B-CHEM', 'I-CHEM', 'B-GEOG', 'I-GEOG', 'B-PHYS', 'I-PHYS', 'B-PHEN', 'I-PHEN', 'B-DISO', 'I-DISO', 'B-OBJC', 'I-OBJC'],
|
84 |
)
|
85 |
),
|
|
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
),
|
88 |
supervised_keys=None,
|
@@ -104,6 +142,11 @@ class QUAERO(datasets.GeneratorBasedBuilder):
|
|
104 |
names = ['O', 'B-LIVB', 'I-LIVB', 'B-PROC', 'I-PROC', 'B-ANAT', 'I-ANAT', 'B-DEVI', 'I-DEVI', 'B-CHEM', 'I-CHEM', 'B-GEOG', 'I-GEOG', 'B-PHYS', 'I-PHYS', 'B-PHEN', 'I-PHEN', 'B-DISO', 'I-DISO', 'B-OBJC', 'I-OBJC'],
|
105 |
)
|
106 |
),
|
|
|
|
|
|
|
|
|
|
|
107 |
}
|
108 |
),
|
109 |
supervised_keys=None,
|
@@ -289,6 +332,7 @@ class QUAERO(datasets.GeneratorBasedBuilder):
|
|
289 |
'document_id': i['document_id'],
|
290 |
"ner_tags": ner_tags_IOB2,
|
291 |
"tokens": i['tokens'],
|
|
|
292 |
})
|
293 |
|
294 |
return dict_out
|
|
|
55 |
|
56 |
_LABELS_BASE = ['DISO', 'DEVI', 'CHEM', 'GEOG', 'OBJC', 'PHEN', 'PHYS', 'LIVB', 'PROC', 'ANAT']
|
57 |
|
58 |
+
class StringIndex:
|
59 |
+
|
60 |
+
def __init__(self, vocab):
|
61 |
+
|
62 |
+
self.vocab_struct = {}
|
63 |
+
|
64 |
+
print("Start building the index!")
|
65 |
+
for t in vocab:
|
66 |
+
|
67 |
+
if len(t) == 0:
|
68 |
+
continue
|
69 |
+
|
70 |
+
# Index terms by their first letter and length
|
71 |
+
key = (t[0], len(t))
|
72 |
+
|
73 |
+
if (key in self.vocab_struct) == False:
|
74 |
+
self.vocab_struct[key] = []
|
75 |
+
|
76 |
+
self.vocab_struct[key].append(t)
|
77 |
+
|
78 |
+
print("Finished building the index!")
|
79 |
+
|
80 |
+
def find(self, t):
|
81 |
+
|
82 |
+
key = (t[0], len(t))
|
83 |
+
|
84 |
+
if (key in self.vocab_struct) == False:
|
85 |
+
return "is_oov"
|
86 |
+
|
87 |
+
return "is_not_oov" if t in self.vocab_struct[key] else "is_oov"
|
88 |
+
|
89 |
+
_VOCAB = StringIndex(vocab=open("./vocabulary_nachos_lowercased.txt","r").read().split("\n"))
|
90 |
+
|
91 |
class QUAERO(datasets.GeneratorBasedBuilder):
|
92 |
"""QUAERO dataset."""
|
93 |
|
|
|
116 |
names = ['O', 'B-LIVB', 'I-LIVB', 'B-PROC', 'I-PROC', 'B-ANAT', 'I-ANAT', 'B-DEVI', 'I-DEVI', 'B-CHEM', 'I-CHEM', 'B-GEOG', 'I-GEOG', 'B-PHYS', 'I-PHYS', 'B-PHEN', 'I-PHEN', 'B-DISO', 'I-DISO', 'B-OBJC', 'I-OBJC'],
|
117 |
)
|
118 |
),
|
119 |
+
"is_oov": datasets.Sequence(
|
120 |
+
datasets.features.ClassLabel(
|
121 |
+
names=['is_not_oov', 'is_oov'],
|
122 |
+
),
|
123 |
+
),
|
124 |
}
|
125 |
),
|
126 |
supervised_keys=None,
|
|
|
142 |
names = ['O', 'B-LIVB', 'I-LIVB', 'B-PROC', 'I-PROC', 'B-ANAT', 'I-ANAT', 'B-DEVI', 'I-DEVI', 'B-CHEM', 'I-CHEM', 'B-GEOG', 'I-GEOG', 'B-PHYS', 'I-PHYS', 'B-PHEN', 'I-PHEN', 'B-DISO', 'I-DISO', 'B-OBJC', 'I-OBJC'],
|
143 |
)
|
144 |
),
|
145 |
+
"is_oov": datasets.Sequence(
|
146 |
+
datasets.features.ClassLabel(
|
147 |
+
names=['is_not_oov', 'is_oov'],
|
148 |
+
),
|
149 |
+
),
|
150 |
}
|
151 |
),
|
152 |
supervised_keys=None,
|
|
|
332 |
'document_id': i['document_id'],
|
333 |
"ner_tags": ner_tags_IOB2,
|
334 |
"tokens": i['tokens'],
|
335 |
+
"is_oov": [_VOCAB.find(tt.lower()) for tt in i['tokens']],
|
336 |
})
|
337 |
|
338 |
return dict_out
|