-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdemo.py
28 lines (23 loc) · 913 Bytes
/
demo.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
from keras.models import load_model
import numpy as np
from emo_utils import *
def sentences_to_indices(X, word_to_index, max_len):
m = X.shape[0]
X_indices = np.zeros((m, max_len))
for i in range(m):
sentence_words = X[i].lower().split()
j = 0
for w in sentence_words:
X_indices[i, j] = word_to_index[w]
j = j + 1
return X_indices
model = load_model('checkpoints/my_model.h5')
word_to_index, index_to_word, word_to_vec_map = read_glove_vecs('data/glove.6B.50d.txt')
maxLen = 10
x_test = np.array(['not feeling happy','I love you so much','let us play ball'])
X_test_indices = sentences_to_indices(x_test, word_to_index, maxLen)
pred = model.predict(X_test_indices)
for i in range(len(x_test)):
x = X_test_indices
num = np.argmax(pred[i])
print(' prediction: ' + x_test[i] + label_to_emoji(num).strip())