def log_perplexity(self, chunk):
"""Return per-word lower bound on log perplexity.
Also logs this and perplexity at INFO level.
"""
vw_data = self._predict(chunk)[1]
corpus_words = sum(cnt for document in chunk for _, cnt in document)
bound = -vw_data['average_loss']
LOG.info("%.3f per-word bound, %.1f perplexity estimate based on a "
"held-out corpus of %i documents with %i words",
bound,
numpy.exp2(-bound),
vw_data['corpus_size'],
corpus_words)
return bound
评论列表
文章目录