MCPcopy Create free account
hub / github.com/OUCMachineLearning/OUCML / evaluate

Function evaluate

AutoML/darts-master/rnn/test.py:88–105  ·  view source on GitHub ↗
(data_source, batch_size=10)

Source from the content-addressed store, hash-verified

86
87
88def evaluate(data_source, batch_size=10):
89 # Turn on evaluation mode which disables dropout.
90 model.eval()
91 total_loss = 0
92 ntokens = len(corpus.dictionary)
93 hidden = model.init_hidden(batch_size)
94 for i in range(0, data_source.size(0) - 1, args.bptt):
95 print(i, data_source.size(0)-1)
96 data, targets = get_batch(data_source, i, args, evaluation=True)
97 targets = targets.view(-1)
98
99 log_prob, hidden = parallel_model(data, hidden)
100 loss = nn.functional.nll_loss(log_prob.view(-1, log_prob.size(2)), targets).data
101
102 total_loss += loss * len(data)
103
104 hidden = repackage_hidden(hidden)
105 return total_loss[0] / len(data_source)
106
107# Load the best saved model.
108model = torch.load(args.model_path)

Callers 1

test.pyFile · 0.70

Calls 3

get_batchFunction · 0.90
repackage_hiddenFunction · 0.90
init_hiddenMethod · 0.80

Tested by

no test coverage detected