-
Notifications
You must be signed in to change notification settings - Fork 0
/
newinput.py
49 lines (29 loc) · 844 Bytes
/
newinput.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
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.keras.preprocessing.text import Tokenizer
import pickle
tokenizer = Tokenizer(num_words=10000)
# In[ ]:
with open('word_index.pickle', 'rb') as handle:
word_index = pickle.load(handle)
# In[ ]:
def rumourdetect(msg):
msg = msg.lower().split(' ')
test_seq = np.array([word_index[word] for word in msg])
test_seq = np.pad(test_seq, (189-len(test_seq), 0),
'constant', constant_values=(0))
test_seq = test_seq.reshape(1, 189)
model = load_model("spammodel.h5")
pred = model.predict_classes(test_seq)
print("pred = " + str(pred[0]))
if pred == [0]:
return 0
elif pred == [1]:
return 1
else:
return 2
# In[ ]:
# In[ ]: