-
Notifications
You must be signed in to change notification settings - Fork 6
/
wordvec_lstm_softmax_predict.py
38 lines (26 loc) · 1.07 KB
/
wordvec_lstm_softmax_predict.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
from random import shuffle
import numpy as np
import sys
import os
def main():
random_state = 42
np.random.seed(random_state)
current_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(current_dir, '..'))
current_dir = current_dir if current_dir is not '' else '.'
model_dir_path = current_dir + '/models'
data_file_path = current_dir + '/data/umich-sentiment-train.txt'
from keras_sentiment_analysis.library.lstm import WordVecLstmSoftmax
from keras_sentiment_analysis.library.utility.simple_data_loader import load_text_label_pairs
text_label_pairs = load_text_label_pairs(data_file_path)
classifier = WordVecLstmSoftmax()
classifier.load_model(model_dir_path=model_dir_path)
shuffle(text_label_pairs)
for i in range(20):
text, label = text_label_pairs[i]
print('Output: ', classifier.predict(sentence=text))
predicted_label = classifier.predict_class(text)
print('Sentence: ', text)
print('Predicted: ', predicted_label, 'Actual: ', label)
if __name__ == '__main__':
main()