forked from ray075hl/Bi-Model-Intent-And-Slot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_dict.py
51 lines (36 loc) · 1.07 KB
/
make_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import config as cfg
def convert_int(arr):
try:
a = int(arr)
except:
return None
return a
# Make words dict
words = []
with open(cfg.train_file) as f:
for line in f.readlines():
line = line.strip().lower().split()
for index, item in enumerate(line):
word = item.split(':')[0]
if word == '<=>':
break
if convert_int(word) is not None:
words.append('DIGIT' * len(word))
else:
words.append(word)
words_vocab = sorted(set(words))
word_dict = {'UNK': 0, 'PAD': 1}
for i, item in enumerate(words_vocab):
word_dict[item] = i + 2
# Make slot tag dict
slot_dict = {}
with open(cfg.vocab_slot_file) as f:
for i, line in enumerate(f.readlines()):
slot_dict[line.strip()] = i
# print(slot_dict)
# Make intent dict
intent_dict = {}
with open(cfg.vocab_intent_file) as f:
for i, line in enumerate(f.readlines()):
intent_dict[line.strip()] = i
# print(intent_dict)