MCPcopy Index your code
hub / github.com/pytorch/tutorials / evaluate

Function evaluate

beginner_source/chatbot_tutorial.py:1184–1199  ·  view source on GitHub ↗
(encoder, decoder, searcher, voc, sentence, max_length=MAX_LENGTH)

Source from the content-addressed store, hash-verified

1182#
1183
1184def evaluate(encoder, decoder, searcher, voc, sentence, max_length=MAX_LENGTH):
1185 ### Format input sentence as a batch
1186 # words -> indexes
1187 indexes_batch = [indexesFromSentence(voc, sentence)]
1188 # Create lengths tensor
1189 lengths = torch.tensor([len(indexes) for indexes in indexes_batch])
1190 # Transpose dimensions of batch to match models' expectations
1191 input_batch = torch.LongTensor(indexes_batch).transpose(0, 1)
1192 # Use appropriate device
1193 input_batch = input_batch.to(device)
1194 lengths = lengths.to("cpu")
1195 # Decode sentence with searcher
1196 tokens, scores = searcher(input_batch, lengths, max_length)
1197 # indexes -> words
1198 decoded_words = [voc.index2word[token.item()] for token in tokens]
1199 return decoded_words
1200
1201
1202def evaluateInput(encoder, decoder, searcher, voc):

Callers 1

evaluateInputFunction · 0.70

Calls 1

indexesFromSentenceFunction · 0.70

Tested by

no test coverage detected