-
Notifications
You must be signed in to change notification settings - Fork 128
/
recursive_rnn_v1_predict.py
35 lines (26 loc) · 1017 Bytes
/
recursive_rnn_v1_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
from __future__ import print_function
import pandas as pd
from keras_text_summarization.library.rnn import RecursiveRNN1
import numpy as np
def main():
np.random.seed(42)
data_dir_path = './data'
model_dir_path = './models'
print('loading csv file ...')
df = pd.read_csv(data_dir_path + "/fake_or_real_news.csv")
# df = df.loc[df.index < 1000]
X = df['text']
Y = df.title
config = np.load(RecursiveRNN1.get_config_file_path(model_dir_path=model_dir_path)).item()
summarizer = RecursiveRNN1(config)
summarizer.load_weights(weight_file_path=RecursiveRNN1.get_weight_file_path(model_dir_path=model_dir_path))
print('start predicting ...')
for i in np.random.permutation(np.arange(len(X)))[0:20]:
x = X[i]
actual_headline = Y[i]
headline = summarizer.summarize(x)
# print('Article: ', x)
print('Generated Headline: ', headline)
print('Original Headline: ', actual_headline)
if __name__ == '__main__':
main()