-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsingle_evaluation.py
30 lines (26 loc) · 1.16 KB
/
single_evaluation.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
from keras.preprocessing.text import Tokenizer
from keras.preprocessing import sequence
from keras.models import model_from_json
import unidecode
import numpy as np
import pickle
import string
import sys
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights("model.h5")
loaded_model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
countries = ["russian", "chinese", "arabic", "germany", "korean", "polish", "scottish", "italian", "english", "french", "japanese", "greece", "spanish", "india", "turkish", "indonesia", "vietnam", "czech"]
tokenizer = pickle.load(open("tokenizer.pc", "rb"))
while True:
print("Enter the name you want to classify: ", flush=True, end="")
name = input("")
name = unidecode.unidecode(name)
X = sequence.pad_sequences(tokenizer.texts_to_sequences([name]), 42, padding='post')
res = loaded_model.predict(X)[0]
res = list(zip(res, countries))
res.sort(reverse=True)
for prob,country in res[:5]:
print("probability %s names = %.2f%%" % (country, float(prob*100)))