/
input_test.py
52 lines (37 loc) · 1.36 KB
/
input_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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from tensorflow.keras.models import load_model
from preprocessing import to_npy, MAX_LEN, MAX_LEN_TITLE, to_npy_2
def text_predict(file_path, model_path='model_final.h5'):
f = open(file_path, "r")
text = f.read()
f.close()
# with open(file_path, 'r') as f:
# text = f.read().replace('\n', '')
model = load_model(model_path)
vec = to_npy(text).reshape(1,MAX_LEN,300)
a = model(vec, training=False)
return a
def string_predict_text(text, model_path='model_final.h5'):
model = load_model(model_path)
vec = to_npy(text).reshape(1,MAX_LEN,300)
a = model(vec, training=False)
b = '%.0f'%(100*float(a[0][1]))+"%"
return b
def string_predict_title(text, model_path='model_title.h5'):
model = load_model(model_path)
vec = to_npy_2(text).reshape(1,MAX_LEN_TITLE,300)
a = model(vec, training=False)
b = '%.0f'%(100*float(a[0][1]))+"%"
return b
def title_predict(file_path, model_path='model_title.h5'):
f = open(file_path, "r")
text = f.read()
f.close()
# with open(file_path, 'r') as f:
# text = f.read().replace('\n', '')
model = load_model(model_path)
vec = to_npy_2(text).reshape(1,MAX_LEN_TITLE,300)
a = model(vec, training=False)
return a
if __name__ == "__main__":
# print(text_predict('test_data/test.txt'))
print(title_predict('test_data/test.txt'))