-
Notifications
You must be signed in to change notification settings - Fork 70
/
predict.py
34 lines (24 loc) · 868 Bytes
/
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
import pandas as pd
import tensorflow as tf
from util import make_w2v_embeddings
from util import split_and_zero_padding
from util import ManDist
# File paths
TEST_CSV = './data/test-20.csv'
# Load training set
test_df = pd.read_csv(TEST_CSV)
for q in ['question1', 'question2']:
test_df[q + '_n'] = test_df[q]
# Make word2vec embeddings
embedding_dim = 300
max_seq_length = 20
test_df, embeddings = make_w2v_embeddings(test_df, embedding_dim=embedding_dim, empty_w2v=False)
# Split to dicts and append zero padding.
X_test = split_and_zero_padding(test_df, max_seq_length)
# Make sure everything is ok
assert X_test['left'].shape == X_test['right'].shape
# --
model = tf.keras.models.load_model('./data/SiameseLSTM.h5', custom_objects={'ManDist': ManDist})
model.summary()
prediction = model.predict([X_test['left'], X_test['right']])
print(prediction)