-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentiment_test.py
More file actions
40 lines (33 loc) · 1000 Bytes
/
Copy pathsentiment_test.py
File metadata and controls
40 lines (33 loc) · 1000 Bytes
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
#Ben Shakow
from __future__ import absolute_import, division, print_function
from keras.models import load_model
import tensorflow as tf
import keras
from keras.preprocessing.text import Tokenizer
import numpy as np
import pickle
model = load_model('modelSave2.h5')
with open('tokenizer.pickle', 'rb') as handle:
token = pickle.load(handle)
def testPhrase(phrase):
doc = keras.preprocessing.text.text_to_word_sequence(phrase, filters='!"#%&()*+,-./:;<=>?@[\\]^_`{|}~\t\n', lower=True, split=" ")
for l in range(len(doc)):
temp = doc[l]
doc[l] = token.word_index.get(temp)
if (doc[l] == None):
doc[l]=0
while len(doc)<35:
doc.append(0)
data = []
data.append(doc)
data = np.array(data)
# print(data)
tested = model.predict(data)
print('The phrase "'+ phrase + '" is ', end='')
if(tested[0]<=.5):
print('bad :(')
else:
print('good!')
print('\n')
print('\n\n')
testPhrase('Hi GitHub!')