yunsukim86 / wbw-lm

Context-aware beam search for unsupervised word-by-word translation
Other
9 stars 1 forks source link

KeyError: tensor(12211, device='cuda:0') #2

Open wingsyuan opened 4 years ago

wingsyuan commented 4 years ago

hi,@yunsukim86

When I used the following command to start the word by word translation (English-Chinese): python translate.py --src_emb /data/home/aaa/mt/dataset/muti-domain/dataset/muti_domain/embedding/muti_domains_en.vec --tgt_emb /data/home/aaa/mt/dataset/muti-domain/dataset/muti_domain/embedding/muti_domains_zh.vec --emb_dim 512 --lm /data/home/aaa/mt/dataset/muti-domain/unmt/data/zh.lm.blm --input /data/home/aaa/mt/dataset/muti-domain/dataset/muti_domain/news/parallel/test/raw/test_2019_tok.en > pre

errors occures as followed loading input data... loading embeddings... normalizing embeddings... loading LM... translating... Traceback (most recent call last): File "translate.py", line 128, in translator.corpus_translation(input_sents, lm) File "/data/home/aaa/mt/wbw-lm/src/evaluation/translator.py", line 145, in corpus_translation trs = self.sent_translation(sent, lm) File "/data/home/aaa/mt/wbw-lm/src/evaluation/translator.py", line 118, in sent_translation topk_tgt_words, topk_scores = self.word_translation(src_word) File "/data/home/aaa/mt/wbw-lm/src/evaluation/translator.py", line 101, in word_translation tgt_word = self.tgt_dico.id2word[topk_tgt_ids[i]] KeyError: tensor(12211, device='cuda:0')

I use the aligned embeddings and unaligned embeddings, and retrained the lm again, it stil failed ,Can you give me some advise? Thanks you very much!!!

yunsukim86 commented 4 years ago

Hi, could you change the line 101 to: tgt_word = self.tgt_dico.id2word[int(topk_tgt_ids[i])] and try again?