Transformer icon indicating copy to clipboard operation
Transformer copied to clipboard

IndexError when testing with python translate.py

Open romran opened this issue 6 years ago • 5 comments

Hello, Many thanks for sharing project, unfortunatelly getting IndexError: index 0 is out of bounds for dimension 0 with size 0 when running on floydhub python translate.py -load_weights weights -src_lang en -trg_lang fr -floyd -no_cuda and parsing text for translation. May someone know where could be the problem?

error

romran avatar Jan 18 '19 13:01 romran

@romran I am getting the same problem for some input texts not all of them. I am not sure where is the issue though

fabrahman avatar Jan 22 '19 21:01 fabrahman

This is due to a bug in the beam search module. I made a pull request with a fix here https://github.com/SamLynnEvans/Transformer/pull/5

You can copy/paste the changes if you just want to try it out :)

oscarberonius avatar Feb 11 '19 11:02 oscarberonius

@oscarberonius Hi Thanks for your effort. It is still giving index error for some inputs. I tried previous inputs which I got error index and it is working on them now. But it throw error for other inputs now.

fabrahman avatar Feb 12 '19 18:02 fabrahman

Hi @Hannabrahman. That is indeed strange, I still don't have any problems with any of my inputs. Maybe yours contain multiple start-tokens?

Anyway, let me know if you find a solution. Good luck!

oscarberonius avatar Feb 20 '19 13:02 oscarberonius

change the code in beam.py as following. It seems there is a bug in the origin code.

the origin code try to stop when there are k eos in the final top k sentence,however, its possible for topi containing more than 1 eos,when this happens, there is a bug

    if (outputs==eos_tok).cpu().numpy().argmax(axis=1).nonzero()[0].shape[0]== opt.k:
        alpha = 0.7
        div = 1 / (torch.tensor(((outputs == eos_tok).cpu().numpy().argmax(axis=1))).type_as(log_scores) ** alpha)
        _, ind = torch.max(log_scores * div, 1)
        ind = ind.data[0]
        break

xiaohongniua avatar Jun 27 '19 09:06 xiaohongniua