-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpredictText.py
More file actions
33 lines (25 loc) · 1.22 KB
/
predictText.py
File metadata and controls
33 lines (25 loc) · 1.22 KB
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
#Minimal example for running location prediction
from keras.models import load_model
import pickle
from keras.preprocessing.sequence import pad_sequences
import numpy as np
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"] = ""
binaryPath= 'data/binaries/' #Place where the serialized training data is
modelPath= 'data/models/' #Place to store the models
#Load Model
textBranch = load_model(modelPath +'/textBranchNorm.h5')
#Load preprocessed data...
file = open(binaryPath +"processors.obj",'rb')
descriptionTokenizer, domainEncoder, tldEncoder, locationTokenizer, sourceEncoder, textTokenizer, nameTokenizer, timeZoneTokenizer, utcEncoder, langEncoder, placeMedian, colnames, classEncoder = pickle.load(file)
#Predict text (e.g., 'Montmartre is truly beautiful')
testTexts=[];
testTexts.append("Montmartre is truly beautiful")
textSequences = textTokenizer.texts_to_sequences(testTexts)
textSequences = np.asarray(textSequences)
textSequences = pad_sequences(textSequences)
predict = textBranch.predict(textSequences)
#Print the top 5
for index in reversed(predict.argsort()[0][-5:]):
print("%s with score=%.3f" % (colnames[index], float(predict[0][index])) )