def TestCorpus()

in source/nli.py [0:0]


    def TestCorpus(self, dset, name=' Dev', nlbl=3, out_fname=None):
        correct = 0
        total = 0
        self.mlp.train(mode=False)
        corr = np.zeros(nlbl, dtype=np.int32)
        if out_fname:
            fp = open(out_fname, 'w')
            fp.write('# outputs target_class predicted_class\n')
        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()
            if out_fname:
                for b in range(outputs.shape[0]):
                    for i in range(nlbl):
                        fp.write('{:f} '.format(outputs[b][i]))
                    fp.write('{:d} {:d}\n'
                             .format(predicted[b], Y[b]))

        print(' | {:4s}: {:5.2f}%'
              .format(name, 100.0 * correct.float() / total), end='')
        # print(' | loss {:6.4f}'.format(loss/total), end='')
        print(' | classes:', end='')
        for i in range(nlbl):
            print(' {:5.2f}'.format(100.0 * corr[i] / total), end='')

        if out_fname:
            fp.close()

        return correct, total