qanastek commited on
Commit
7fedb50
·
1 Parent(s): 9e8df72

Update DEFT2021.py

Browse files
Files changed (1) hide show
  1. DEFT2021.py +39 -0
DEFT2021.py CHANGED
@@ -41,6 +41,39 @@ _SPECIALITIES = ['immunitaire', 'endocriniennes', 'blessures', 'chimiques', 'eta
41
 
42
  _LABELS_BASE = ['anatomie', 'date', 'dose', 'duree', 'examen', 'frequence', 'mode', 'moment', 'pathologie', 'sosy', 'substance', 'traitement', 'valeur']
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  class DEFT2021(datasets.GeneratorBasedBuilder):
45
 
46
  DEFAULT_CONFIG_NAME = "ner"
@@ -65,6 +98,11 @@ class DEFT2021(datasets.GeneratorBasedBuilder):
65
  "specialities_one_hot": datasets.Sequence(
66
  datasets.Value("float"),
67
  ),
 
 
 
 
 
68
  }
69
  )
70
 
@@ -624,6 +662,7 @@ class DEFT2021(datasets.GeneratorBasedBuilder):
624
  "document_id": h['document_id'],
625
  "tokens": h['tokens'],
626
  "ner_tags": h['ner_tags'],
 
627
  })
628
 
629
  key += 1
 
41
 
42
  _LABELS_BASE = ['anatomie', 'date', 'dose', 'duree', 'examen', 'frequence', 'mode', 'moment', 'pathologie', 'sosy', 'substance', 'traitement', 'valeur']
43
 
44
+ class StringIndex:
45
+
46
+ def __init__(self, vocab):
47
+
48
+ self.vocab_struct = {}
49
+
50
+ print("Start building the index!")
51
+ for t in vocab:
52
+
53
+ if len(t) == 0:
54
+ continue
55
+
56
+ # Index terms by their first letter and length
57
+ key = (t[0], len(t))
58
+
59
+ if (key in self.vocab_struct) == False:
60
+ self.vocab_struct[key] = []
61
+
62
+ self.vocab_struct[key].append(t)
63
+
64
+ print("Finished building the index!")
65
+
66
+ def find(self, t):
67
+
68
+ key = (t[0], len(t))
69
+
70
+ if (key in self.vocab_struct) == False:
71
+ return "is_oov"
72
+
73
+ return "is_not_oov" if t in self.vocab_struct[key] else "is_oov"
74
+
75
+ _VOCAB = StringIndex(vocab=open("./vocabulary_nachos_lowercased.txt","r").read().split("\n"))
76
+
77
  class DEFT2021(datasets.GeneratorBasedBuilder):
78
 
79
  DEFAULT_CONFIG_NAME = "ner"
 
98
  "specialities_one_hot": datasets.Sequence(
99
  datasets.Value("float"),
100
  ),
101
+ "is_oov": datasets.Sequence(
102
+ datasets.features.ClassLabel(
103
+ names=['is_not_oov', 'is_oov'],
104
+ ),
105
+ ),
106
  }
107
  )
108
 
 
662
  "document_id": h['document_id'],
663
  "tokens": h['tokens'],
664
  "ner_tags": h['ner_tags'],
665
+ "is_oov": [_VOCAB.find(tt) for tt in h['tokens']]
666
  })
667
 
668
  key += 1