forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
40 lines (31 loc) · 1.2 KB
/
test.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
import os
# os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # see issue #152
# os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
# import tensorflow as tf
# config = tf.ConfigProto(intra_op_parallelism_threads=5,
# inter_op_parallelism_threads=5,
# allow_soft_placement=True,
# device_count = {'CPU' : 1,
# 'GPU' : 0}
# )
from utils import get_model, int2label, label2int
from keras.preprocessing.sequence import pad_sequences
import pickle
import numpy as np
SEQUENCE_LENGTH = 100
# get the tokenizer
tokenizer = pickle.load(open("results/tokenizer.pickle", "rb"))
model = get_model(tokenizer, 128)
model.load_weights("results/spam_classifier_0.05")
def get_predictions(text):
sequence = tokenizer.texts_to_sequences([text])
# pad the sequence
sequence = pad_sequences(sequence, maxlen=SEQUENCE_LENGTH)
# get the prediction
prediction = model.predict(sequence)[0]
# one-hot encoded vector, revert using np.argmax
return int2label[np.argmax(prediction)]
while True:
text = input("Enter the mail:")
# convert to sequences
print(get_predictions(text))