natural language toolkit c 20012023 nltk project ilia kurenkov ilia kurenkovgmail com url https www nltk org for license information see license txt language model utilities from math import log neginf floatinf posinf floatinf def logbase2score natural language toolkit c 2001 2023 nltk project ilia kurenkov ilia kurenkov gmail com url https www nltk org for license information see license txt language model utilities convenience function for computing logarithms with base 2
from math import log

NEG_INF = float("-inf")
POS_INF = float("inf")


def log_base2(score):
    
    if score == 0.0:
        return NEG_INF
    return log(score, 2)