qanastek commited on
Commit
f8b8612
·
1 Parent(s): d32d58e

Update E3C.py

Browse files
Files changed (1) hide show
  1. E3C.py +39 -0
E3C.py CHANGED
@@ -36,6 +36,39 @@ _URL = "https://github.com/hltfbk/E3C-Corpus/archive/refs/tags/v2.0.0.zip"
36
 
37
  _LANGUAGES = ["English","Spanish","Basque","French","Italian"]
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  class E3C(datasets.GeneratorBasedBuilder):
40
 
41
  BUILDER_CONFIGS = [
@@ -68,6 +101,11 @@ class E3C(datasets.GeneratorBasedBuilder):
68
  names=names,
69
  ),
70
  ),
 
 
 
 
 
71
  }
72
  )
73
 
@@ -249,6 +287,7 @@ class E3C(datasets.GeneratorBasedBuilder):
249
  "text": sentence[-1],
250
  "tokens": list(map(lambda token: token[2], filtered_tokens)),
251
  "ner_tags": _labels,
 
252
  })
253
 
254
  key += 1
 
36
 
37
  _LANGUAGES = ["English","Spanish","Basque","French","Italian"]
38
 
39
+ class StringIndex:
40
+
41
+ def __init__(self, vocab):
42
+
43
+ self.vocab_struct = {}
44
+
45
+ print("Start building the index!")
46
+ for t in vocab:
47
+
48
+ if len(t) == 0:
49
+ continue
50
+
51
+ # Index terms by their first letter and length
52
+ key = (t[0], len(t))
53
+
54
+ if (key in self.vocab_struct) == False:
55
+ self.vocab_struct[key] = []
56
+
57
+ self.vocab_struct[key].append(t)
58
+
59
+ print("Finished building the index!")
60
+
61
+ def find(self, t):
62
+
63
+ key = (t[0], len(t))
64
+
65
+ if (key in self.vocab_struct) == False:
66
+ return "is_oov"
67
+
68
+ return "is_not_oov" if t in self.vocab_struct[key] else "is_oov"
69
+
70
+ _VOCAB = StringIndex(vocab=open("./vocabulary_nachos_lowercased.txt","r").read().split("\n"))
71
+
72
  class E3C(datasets.GeneratorBasedBuilder):
73
 
74
  BUILDER_CONFIGS = [
 
101
  names=names,
102
  ),
103
  ),
104
+ "is_oov": datasets.Sequence(
105
+ datasets.features.ClassLabel(
106
+ names=['is_not_oov', 'is_oov'],
107
+ ),
108
+ ),
109
  }
110
  )
111
 
 
287
  "text": sentence[-1],
288
  "tokens": list(map(lambda token: token[2], filtered_tokens)),
289
  "ner_tags": _labels,
290
+ "is_oov": [_VOCAB.find(tt.lower()) for tt in list(map(lambda token: token[2], filtered_tokens))],
291
  })
292
 
293
  key += 1