Python 我的Bigram模型没有返回任何值。为什么?

Python 我的Bigram模型没有返回任何值。为什么?,python,nlp,Python,Nlp,我正在用Python中的拉普拉斯平滑构建一个二元语言模型。我编写了下面的类,但是当我尝试在score函数中打印时,它没有打印任何内容,因为该函数正在计算的是的对数概率值,为什么?代码中有什么错误? 我给了一个语料库,它被标记为输入。示例语料库:STOP to be to be STOP class BiGramModel: def __init__(self, corpus): """Initialize your data structures in t

我正在用Python中的拉普拉斯平滑构建一个二元语言模型。我编写了下面的类,但是当我尝试在score函数中打印时,它没有打印任何内容,因为该函数正在计算的是的对数概率值,为什么?代码中有什么错误? 我给了一个语料库,它被标记为输入。示例语料库:STOP to be to be STOP

class BiGramModel:
        def __init__(self, corpus):
            """Initialize your data structures in the constructor."""
            self.unigramCounts = {}
            self.bigramCounts = {}
            self.train(corpus)

        def train(self, corpus):

            for sentence in corpus.corpus:
                previous_token = ""
                for datum in sentence.data:
                    token = datum.word
                    if token in self.unigramCounts:
                        self.unigramCounts[token] = self.unigramCounts[token] + 1.0
                    else:
                        self.unigramCounts[token] = 1.0
                    if previous_token != "":
                        bigram = previous_token + " | " + token                             
                        if bigram in self.bigramCounts:
                            self.bigramCounts[bigram] = self.bigramCounts[bigram] + 1.0
                        else:
                            self.bigramCounts[bigram] = 1.0
                    previous_token = token

        def score(self, sentence):
    "It takes a list of strings as argument and returns the log-probability of the 
    sentence using the bigram language model."
    score = 1.0
    vocabulary = len(self.bigramCounts) + 0.0       
    previous_token = ""
    for token in sentence:
        unigram_find = self.unigramCounts[token] if token in self.unigramCounts else 0.0
        bigram = previous_token + " | " + token
        bigram_find = self.bigramCounts[bigram] if bigram in self.bigramCounts else 0.0                     
        score += math.log(bigram_find + 1.0)
        score -= math.log(unigram_find + vocabulary)
        previous_token = token
    return score

为什么它没有给我任何输出?

我看不到任何打印语句。。。此外,缩进似乎是错误的。语料库是什么样的数据结构?-您访问corpus.corpus中句子行中的属性corpus.corpus;请帮个忙,我们可以帮忙。