How-to-build-own-text-summarizer-using-deep-learning
How-to-build-own-text-summarizer-using-deep-learning copied to clipboard
KeyError
I have got this key error. Please help me. Thank you KeyError Traceback (most recent call last)
KeyError: 0
sampled_token_index = np.argmax(output_tokens[0, -1, :]) + 2
solved here: https://github.com/aravindpai/How-to-build-own-text-summarizer-using-deep-learning/issues/3
Thank @shifatul-i for your help
Key error issue is ok and I have got empty predicted summary like this. Please help me for error.
Thank you so much
I was successfully able to run the entire code set on the problem I am working on.
when I run apply the code to my problem, I get the following output for the code as follows.
Code: for i in range(len(x_val)): print(“Review:”,seq2text(x_val[i])) print(“Original summary:”,seq2summary(y_val[i])) print(“Predicted summary:”,decode_sequence(x_val[i].reshape(1,max_text_len))) print("\n")
Output example: Review: please serial number issue truck Original summary: over the truck and found the and forward not working with good and the issues is picked up new parts from the shop returned Predicted summary: located truck and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and
How do I fix the output to get a better result. Any help would be highly appreciated. Thanks.
I was successfully able to run the entire code set on the problem I am working on.
when I run apply the code to my problem, I get the following output for the code as follows.
Code: for i in range(len(x_val)): print(“Review:”,seq2text(x_val[i])) print(“Original summary:”,seq2summary(y_val[i])) print(“Predicted summary:”,decode_sequence(x_val[i].reshape(1,max_text_len))) print("\n")
Output example: Review: please serial number issue truck Original summary: over the truck and found the and forward not working with good and the issues is picked up new parts from the shop returned Predicted summary: located truck and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and and
How do I fix the output to get a better result. Any help would be highly appreciated. Thanks.
Facing similar issue
It looks like your models are overfitting. @VJSo007 @shrenik007 Did you set dropout = 0.4 and recurrent_dropout=0.4 in your LSTM layers?
If yes, you can improve text generation by applying a randomness, or even better beam-search.
Randomness can be applying be using
sampled_token_index = np.random.choice(len(prediction_output), p=prediction_output)
in decode_sequence()
Thats my decode_sentence function: `def decode_sequence(input_seq): # Encode the input as state vectors. e_out, e_h, e_c = encoder_model.predict(input_seq) print(e_out.shape) print(e_h.shape) print(e_c.shape) # Generate empty target sequence of length 1. target_seq = np.zeros((1,1))
# Chose the 'start' word as the first word of the target sequence
target_seq[0, 0] = target_word_index['sostock']
print(np.array(target_seq).shape)
print(e_out.shape)
print(e_h.shape)
print(e_c.shape)
stop_condition = False
decoded_sentence = ''
while not stop_condition:
output_tokens, h, c = decoder_model.predict([[target_seq] + [e_out, e_h, e_c]])
output_tokens = output_tokens[:1]
h_1 = h[:1]
c_1 = c[:1]
# Sample a token
#Use a random choice as described in this stackoverflow solution:
#https://stackoverflow.com/questions/47125723/keras-lstm-for-text-generation-keeps-repeating-a-line-or-a-sequence
#sampled_token_index = np.argmax(output_tokens[0, -1, :])
prediction_output = output_tokens[0,-1,:]
print(output_tokens)
sampled_token_index = np.random.choice(len(prediction_output), p=prediction_output)
sampled_token = reverse_target_word_index[sampled_token_index]
if(sampled_token!='eostock'):
decoded_sentence += ' '+sampled_token
# Exit condition: either hit max length or find stop word.
if (sampled_token == 'eostock' or len(decoded_sentence.split()) >= (max_len_summary-1)):
stop_condition = True
# Update the target sequence (of length 1).
target_seq = np.zeros((1,1))
target_seq[0, 0] = sampled_token_index
# Update internal states
e_h, e_c = h, c
return decoded_sentence`