Tut 6: TypeError with calculate_bleu_alt
yuvaraj91 opened this issue · 1 comments
yuvaraj91 commented
Using the alternate method for calculating the BLEU score in Tutorial 6, I get this error:
bleu_score = calculate_bleu_alt(test_data, SRC, TRG, model, device)
print(f'BLEU score = {bleu_score*100:.2f}')
TypeError Traceback (most recent call last)
<ipython-input-50-9dbd66c5224c> in <module>()
----> 1 bleu_score = calculate_bleu_alt(test_data, SRC, TRG, model, device)
2
3 print(f'BLEU score = {bleu_score*100:.2f}')
<ipython-input-49-f73b8e937593> in calculate_bleu_alt(iterator, src_field, trg_field, model, device, max_len)
16 if i == trg_field.vocab.stoi[trg_field.eos_token] or i == trg_field.vocab.stoi[trg_field.pad_token]:
17 break
---> 18 tmp.append(trg_field.vocab.itos[i])
19 _trgs.append([tmp])
20 trgs += _trgs
TypeError: list indices must be integers or slices, not str
yuvaraj91 commented
Tried using this suggestion but it did not work:
I fixed this issue with replace on calculate_bleu_alt function
return pred_trgs, trgs, bleu_score(pred_trgs, trgs)
like this
return bleu_score(pred_trgs, trgs)
Any tips, @bentrevett ?