MCPcopy Create free account
hub / github.com/OpenBMB/DecT / FewNERDProcessor

Class FewNERDProcessor

src/process_data.py:306–370  ·  view source on GitHub ↗

`Few-NERD `_ a large-scale, fine-grained manually annotated named entity recognition dataset It was released together with `Few-NERD: Not Only a Few-shot NER Dataset (Ning Ding et al. 2021) `_

Source from the content-addressed store, hash-verified

304 return examples
305
306class FewNERDProcessor(DataProcessor):
307 """
308 `Few-NERD <https://ningding97.github.io/fewnerd/>`_ a large-scale, fine-grained manually annotated named entity recognition dataset
309
310 It was released together with `Few-NERD: Not Only a Few-shot NER Dataset (Ning Ding et al. 2021) <https://arxiv.org/pdf/2105.07464.pdf>`_
311 """
312 def __init__(self):
313 super().__init__()
314 self.labels = [
315 "person-actor", "person-director", "person-artist/author", "person-athlete", "person-politician", "person-scholar", "person-soldier", "person-other",
316 "organization-showorganization", "organization-religion", "organization-company", "organization-sportsteam", "organization-education", "organization-government/governmentagency", "organization-media/newspaper", "organization-politicalparty", "organization-sportsleague", "organization-other",
317 "location-GPE", "location-road/railway/highway/transit", "location-bodiesofwater", "location-park", "location-mountain", "location-island", "location-other",
318 "product-software", "product-food", "product-game", "product-ship", "product-train", "product-airplane", "product-car", "product-weapon", "product-other",
319 "building-theater", "building-sportsfacility", "building-airport", "building-hospital", "building-library", "building-hotel", "building-restaurant", "building-other",
320 "event-sportsevent", "event-attack/battle/war/militaryconflict", "event-disaster", "event-election", "event-protest", "event-other",
321 "art-music", "art-writtenart", "art-film", "art-painting", "art-broadcastprogram", "art-other",
322 "other-biologything", "other-chemicalthing", "other-livingthing", "other-astronomything", "other-god", "other-law", "other-award", "other-disease", "other-medical", "other-language", "other-currency", "other-educationaldegree",
323 ]
324
325 def get_examples(self, data_dir, split):
326 path = os.path.join(data_dir, "supervised/{}.txt".format(split))
327 with open(path, encoding='utf8') as f:
328 data = FewNERDProcessor.load_data(f)
329
330 examples = []
331
332 for idx, (xs, ys, spans) in enumerate(data):
333 for span in spans:
334 text_a = " ".join(xs)
335 meta = {
336 "entity": " ".join(xs[span[0]: span[1]+1])
337 }
338 example = InputExample(guid=str(idx), text_a=text_a, meta=meta, label=self.get_label_id(ys[span[0]][2:]))
339 examples.append(example)
340
341 return examples
342
343 @staticmethod
344 def load_data(file):
345 data = []
346 xs = []
347 ys = []
348 spans = []
349
350 for line in file.readlines():
351 pair = line.split()
352 if pair == []:
353 if xs != []:
354 data.append((xs, ys, spans))
355 xs = []
356 ys = []
357 spans = []
358 else:
359 xs.append(pair[0])
360
361 tag = pair[-1]
362 if tag != 'O':
363 if len(ys) == 0 or tag != ys[-1][2:]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected