gabrielaltay commited on
Commit
db2b0ec
1 Parent(s): 063509a

upload bigbiohub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. bigbiohub.py +37 -1
bigbiohub.py CHANGED
@@ -163,6 +163,40 @@ kb_features = datasets.Features(
163
  )
164
 
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  def get_texts_and_offsets_from_bioc_ann(ann: "bioc.BioCAnnotation") -> Tuple:
167
 
168
  offsets = [(loc.offset, loc.offset + loc.length) for loc in ann.locations]
@@ -304,9 +338,11 @@ def parse_brat_file(
304
  ann_lines = []
305
  for suffix in annotation_file_suffixes:
306
  annotation_file = txt_file.with_suffix(suffix)
307
- if annotation_file.exists():
308
  with annotation_file.open() as f:
309
  ann_lines.extend(f.readlines())
 
 
310
 
311
  example["text_bound_annotations"] = []
312
  example["events"] = []
163
  )
164
 
165
 
166
+ TASK_TO_SCHEMA = {
167
+ Tasks.NAMED_ENTITY_RECOGNITION.name: "KB",
168
+ Tasks.NAMED_ENTITY_DISAMBIGUATION.name: "KB",
169
+ Tasks.EVENT_EXTRACTION.name: "KB",
170
+ Tasks.RELATION_EXTRACTION.name: "KB",
171
+ Tasks.COREFERENCE_RESOLUTION.name: "KB",
172
+ Tasks.QUESTION_ANSWERING.name: "QA",
173
+ Tasks.TEXTUAL_ENTAILMENT.name: "TE",
174
+ Tasks.SEMANTIC_SIMILARITY.name: "PAIRS",
175
+ Tasks.TEXT_PAIRS_CLASSIFICATION.name: "PAIRS",
176
+ Tasks.PARAPHRASING.name: "T2T",
177
+ Tasks.TRANSLATION.name: "T2T",
178
+ Tasks.SUMMARIZATION.name: "T2T",
179
+ Tasks.TEXT_CLASSIFICATION.name: "TEXT",
180
+ }
181
+
182
+ SCHEMA_TO_TASKS = defaultdict(set)
183
+ for task, schema in TASK_TO_SCHEMA.items():
184
+ SCHEMA_TO_TASKS[schema].add(task)
185
+ SCHEMA_TO_TASKS = dict(SCHEMA_TO_TASKS)
186
+
187
+ VALID_TASKS = set(TASK_TO_SCHEMA.keys())
188
+ VALID_SCHEMAS = set(TASK_TO_SCHEMA.values())
189
+
190
+ SCHEMA_TO_FEATURES = {
191
+ "KB": kb_features,
192
+ "QA": qa_features,
193
+ "TE": entailment_features,
194
+ "T2T": text2text_features,
195
+ "TEXT": text_features,
196
+ "PAIRS": pairs_features,
197
+ }
198
+
199
+
200
  def get_texts_and_offsets_from_bioc_ann(ann: "bioc.BioCAnnotation") -> Tuple:
201
 
202
  offsets = [(loc.offset, loc.offset + loc.length) for loc in ann.locations]
338
  ann_lines = []
339
  for suffix in annotation_file_suffixes:
340
  annotation_file = txt_file.with_suffix(suffix)
341
+ try:
342
  with annotation_file.open() as f:
343
  ann_lines.extend(f.readlines())
344
+ except Exception:
345
+ continue
346
 
347
  example["text_bound_annotations"] = []
348
  example["events"] = []