def validate(self, model, num_ngrams, batch_size, num_batches):
        """
        Return average negative log-likelihood
        """
        loss = 0.0
        for i in xrange(num_batches):
            ngram_start_id = i * batch_size
            ngram_end_id = (i + 1) * batch_size if i < (num_batches - 1) else num_ngrams
            loss -= model(ngram_start_id, ngram_end_id)  # model returns sum log likelihood
        loss /= num_ngrams
        perp = np.exp(loss)
        return (loss, perp)
dataset/ETHPy150Open yuhaozhang/nnjm-global/code/train_nnjm.py/TrainNNJMModel.validate/original