'IndexError: tuple index out of range BLSTM

Please Help me, i want to generate and evaluating accuracy of text summarize model. When i call the evaluating model and generating text from the vector, i just got error tuple index out of range, and what i know the shape in the model was already customized by me.

This is the code :

MAX_LEN = 300

en_shape=np.shape(MAX_LEN,)
de_shape=np.shape(MAX_LEN,)

def generateText(SentOfVecs):
SentOfVecs=np.reshape(SentOfVecs,de_shape)
kk=""
for k in SentOfVecs:
    kk = kk + label_encoder.inverse_transform([argmax(k)])[0].strip()+" "
    #kk=kk+((getWord(k)[0]+" ") if getWord(k)[1]>0.01 else "")
return kk

def summarize(article):
stop_pred = False
article =  np.reshape(article,(1,en_shape[0],en_shape[1]))
#get initial h and c values from encoder
init_state_val = encoder.predict(article)
target_seq = np.zeros((1,1,de_shape[1]))
#target_seq =np.reshape(train_data['summaries'][k][0],(1,1,de_shape[1]))
generated_summary=[]
while not stop_pred:
    decoder_out,decoder_h,decoder_c= decoder.predict(x=[target_seq]+init_state_val)
    generated_summary.append(decoder_out)
    init_state_val= [decoder_h,decoder_c]
    #get most similar word and put in line to be input in next timestep
    #target_seq=np.reshape(model.wv[getWord(decoder_out)[0]],(1,1,emb_size_all))
    target_seq=np.reshape(decoder_out,(1,1,de_shape[1]))
    if len(generated_summary)== de_shape[0]:
        stop_pred=True
        break
return generated_summary

def evaluate_summ(article):
ref=''
for k in wt(train_data['gold_summary'][article])[:20]:
    ref=ref+' '+k
gen_sum = generateText(summarize(train_data["article"][article]))
print("-----------------------------------------------------")
print("Original summary")
print(ref)
print("-----------------------------------------------------")
print("Generated summary")
print(gen_sum)
print("-----------------------------------------------------")
rouge = Rouge155()
score = rouge.score_summary(ref, gen_sum)
print("Rouge1 Score: ",score)

And this was the error i got :

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-73-033edff49496> in <module>()
----> 1 evaluate_summ(10)
      2 
      3 print(generateText(summarize(train_data["text_clean"][8])))
      4 print(train_data["gold_summary"][8])
      5 print(train_data["article"][8])

1 frames
<ipython-input-72-c6ea0ce23227> in evaluate_summ(article)
     36     for k in wt(train_data['gold_summary'][article])[:20]:
     37         ref=ref+' '+k
---> 38     gen_sum = generateText(summarize(train_data["article"][article]))
     39     print("-----------------------------------------------------")
     40     print("Original summary")

<ipython-input-72-c6ea0ce23227> in summarize(article)
     14 def summarize(article):
     15     stop_pred = False
---> 16     article =  np.reshape(article,(1,en_shape[0],en_shape[1]))
     17     #get initial h and c values from encoder
     18     init_state_val = encoder.predict(article)

IndexError: tuple index out of range


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source