Я следую руководству по НЛП здесь (6'58'') — раздел о алгоритм сглаживания глупых отставаний. В обучающем видео и реализация уровня биграмм глупый-откат, они используют значение скидки = 0,4
Реализовать отсрочку на уровне биграммы:
def score(self, sentence):
score = 0.0
previous = sentence[0]
for token in sentence[1:]:
bicount = self.bigramCounts[(previous, token)]
bi_unicount = self.unigramCounts[previous]
unicount = self.unigramCounts[token]
if bicount > 0:
score += math.log(bicount)
score -= math.log(bi_unicount)
else:
score += math.log(0.4) // discount here
score += math.log(unicount + 1)
score -= math.log(self.total + self.vocab_size)
previous = token
return score
Но затем в реализации на уровне триграммы значение скидки равно 1.
def score(self, sentence):
score = 0.0
fst = sentence[0]
snd = sentence[1]
for token in sentence[2:]:
tricount = self.trigramCounts[(fst, snd, token)]
tri_bicount = self.bigramCounts[(fst, snd)]
bicount = self.bigramCounts[(snd, token)]
bi_unicount = self.unigramCounts[snd]
unicount = self.unigramCounts[token]
if tricount > 0:
score += math.log(tricount)
score -= math.log(tri_bicount)
elif bicount > 0:
score += math.log(bicount) // no discount here
score -= math.log(bi_unicount)
else:
score += math.log((unicount + 1)) // no discount here
score -= math.log(self.total + self.vocab_size)
fst, snd = snd, token
return score
когда я запустил проект - обе скидки были установлены на 0,4 и 1 за уровень триграмм, я получил оценку:
tri-gram with discount = 0.4
< bi-gram with discount = 0.4
< tri-gram with discount =1
Легко понять, почему - со скидкой = 0,4 конечные else
триграммы становятся:
else:
score += math.log(0.4) // -> -0.3979
score += math.log(0.4) // -> -0.3979
score += math.log((unicount + 1)) // no discount here
score -= math.log(self.total + self.vocab_size)
Так что я действительно запутался - откуда взялось значение 0,4?