MCPcopy Create free account
hub / github.com/pytorch/tutorials / evaluate

Function evaluate

intermediate_source/seq2seq_translation_tutorial.py:734–750  ·  view source on GitHub ↗
(encoder, decoder, sentence, input_lang, output_lang)

Source from the content-addressed store, hash-verified

732#
733
734def evaluate(encoder, decoder, sentence, input_lang, output_lang):
735 with torch.no_grad():
736 input_tensor = tensorFromSentence(input_lang, sentence)
737
738 encoder_outputs, encoder_hidden = encoder(input_tensor)
739 decoder_outputs, decoder_hidden, decoder_attn = decoder(encoder_outputs, encoder_hidden)
740
741 _, topi = decoder_outputs.topk(1)
742 decoded_ids = topi.squeeze()
743
744 decoded_words = []
745 for idx in decoded_ids:
746 if idx.item() == EOS_token:
747 decoded_words.append('<EOS>')
748 break
749 decoded_words.append(output_lang.index2word[idx.item()])
750 return decoded_words, decoder_attn
751
752
753######################################################################

Callers 3

evaluateRandomlyFunction · 0.70
evaluateAndShowAttentionFunction · 0.70

Calls 1

tensorFromSentenceFunction · 0.85

Tested by

no test coverage detected