in source/sent_classif.py [0:0]
def TestCorpus(self, dset, name=' Dev', nlbl=4):
correct = 0
total = 0
self.mlp.train(mode=False)
corr = np.zeros(nlbl, dtype=np.int32)
for data in dset:
X, Y = data
Y = Y.long()
if self.gpu >= 0:
X = X.cuda()
Y = Y.cuda()
outputs = self.mlp(X)
_, predicted = torch.max(outputs.data, 1)
total += Y.size(0)
correct += (predicted == Y).int().sum()
for i in range(nlbl):
corr[i] += (predicted == i).int().sum()
print(' | {:4s}: {:5.2f}%'
.format(name, 100.0 * correct.float() / total), end='')
print(' | classes:', end='')
for i in range(nlbl):
print(' {:5.2f}'.format(100.0 * corr[i] / total), end='')
return correct, total