You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
450 B
Python
20 lines
450 B
Python
# Natural Language Toolkit
|
|
#
|
|
# Copyright (C) 2001-2020 NLTK Project
|
|
# Author: Ilia Kurenkov <ilia.kurenkov@gmail.com>
|
|
# URL: <http://nltk.org/>
|
|
# For license information, see LICENSE.TXT
|
|
"""Language Model Utilities"""
|
|
|
|
from math import log
|
|
|
|
NEG_INF = float("-inf")
|
|
POS_INF = float("inf")
|
|
|
|
|
|
def log_base2(score):
|
|
"""Convenience function for computing logarithms with base 2."""
|
|
if score == 0.0:
|
|
return NEG_INF
|
|
return log(score, 2)
|