-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
34 lines (27 loc) · 1.02 KB
/
predict.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
#!/usr/bin/env python
from load_data_amz import SentimentsData
from keras.models import load_model
from keras.optimizers import Adam
from keras.preprocessing import sequence
print("Loading model...")
model = load_model("models/sentiments_full_glove_embeddings.hdf5")
model.compile(loss='binary_crossentropy',
optimizer=Adam(),
metrics=['accuracy'])
model.summary()
print("Get the data to predict on...")
sd = SentimentsData()
print('Loading data...')
(x_train, y_train), (x_test, y_test) = sd.load()
max_features = sd.corpus_size
maxlen = 1000 #sd.max_size # cut texts after this number of words (among top max_features most common words)
batch_size = 64
sd.create_embeddings_matrix()
print('Pad sequences (samples x time)')
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
print('Predict...')
score, acc = model.evaluate(x_train, y_train,
batch_size=batch_size)
print('Test score:', score)
print('Test accuracy:', acc)