-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
29 lines (22 loc) · 1.48 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
from keras.models import load_model
from keras.preprocessing.sequence import pad_sequences
import pickle
import json
import numpy as np
import pandas as pd
# load the tokenizer and the model
with open("keras_tokenizer.pickle", "rb") as f:
tokenizer = pickle.load(f)
model = load_model("yelp_sentiment_model.hdf5")
# replace with the data you want to classify
newtexts = ["Clean, nice and professional service. Friendly team. Also my order was very delicious. Strongly recommend you this place", "Very organized and efficient. And people working behind the counter are actually friendly and don't seem like they hate their jobs and hate you. Food did take a few minutes to come out since they were so busy. Overall, a good experience","Only came in here to use the bathroom because the 9/11 Memorial doesn't have Any! Separate lines for men & women - each only has 1 toilet/1 sink!","fuck this shitty place. workers dont give a damn fuck about this place. slow as fuck. esp the main indian women working takes her slow ass time when people are wait ing like wow service is so damn bad"]
# note that we shouldn't call "fit" on the tokenizer again
sequences = tokenizer.texts_to_sequences(newtexts)
data = pad_sequences(sequences, maxlen=300)
# get predictions for each of your new texts
predictions = model.predict(data)
predictionsdf = pd.DataFrame(data=predictions)
print(predictionsdf)
#predictionsList = np.ndarray.tolist(predictions)
#jsonPredictions = json.dumps(predictionsList)
#print(jsonPredictions)