-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredictions.py
58 lines (43 loc) · 1.23 KB
/
predictions.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
52
53
54
55
56
57
58
import numpy as np
import json
from support import get_languages
from wordfreq import zipf_frequency
from tensorflow.keras.models import load_model
MAX_LEN = 20
sentence = 'piacere di conoscerti'
sentence = sentence.lower()
predictions = []
count = 0
words_directory = 'C:/Users/Samuel/Desktop/my_version/dictionaries/'
master_data = []
lang_short = ['en','fr','it','es']
lang = ['english', 'french', 'italian', 'spanish']
data_dir = 'C:/Users/Samuel/Desktop/my_version/sentences_list'
count = 0
temp = []
for lan in lang_short:
local = []
d = json.load(open(words_directory+str(lan)+'_dic.json'))
for words in sentence.lower().split():
if words in d:
local.append(10001 - d[words])
else:
local.append(0)
if len(local)>MAX_LEN:
local = local[:MAX_LEN]
if len(local)<MAX_LEN:
local += [0 for _ in range(MAX_LEN-len(local))]
temp.append(local)
for x in temp:
print(x)
temp = np.array(temp)
temp = (temp/10001) * 255
final = []
final.append(temp)
print(np.shape(final))
final = np.array(final, dtype=np.float32)
final = final.reshape(final.shape[0],4,20,1)
model = load_model('model.h5')
predictions = np.argmax(model.predict(final))
count=0
print(predictions)