I am trying to create a Japanese-English translation model following this Medium article. https://arusl.medium.com/japanese-english-language-translation-with-transformer-using-pytorch-243738146806 Everything runs perfectly until the second to last cell, when I get an error running the translate function. The error is specifically on this line.
tokens = [BOS_IDX] + [src_vocab.stoi[tok] for tok in src_tokenizer.encode(src, out_type=str)]+ [EOS_IDX]
错误:AttributeError: Vocabbject没有属性。 自撰写文章以来,根据火rch文献(,对手法进行了修改。 然而,当我试图将这一条线改为以下时,我就犯了错误,即“国家物体没有属性。
tokens = [BOS_IDX] + [src_vocab.get_stoi()[tok] for tok in src_tokenizer.encode(src, out_type=str)]+ [EOS_IDX]
The same goes for the itos and get_itos() method. If I try to use the method as Any help for how to make this work would be greatly appreciated as I m very dumbfounded at the moment.
这里也提出了类似的问题,但我看不出如何落实答案或如何在本案中发挥作用。 Vocab 物体没有特性。
Edit: This function seems suspect as it is creating vocab out of a counter... is there a better way to do this?
def build_vocab(sentences, tokenizer):
counter = Counter()
for sentence in sentences:
counter.update(tokenizer.encode(sentence, out_type=str))
return Vocab(counter)
Thank you!