smoothing

This commit is contained in:
Bartosz Karwacki 2022-04-10 18:43:05 +02:00
parent d71b99be29
commit 2b253e5c4f
3 changed files with 1297 additions and 1298 deletions

File diff suppressed because it is too large Load Diff

9
run.py
View File

@ -41,15 +41,14 @@ class Model:
for w1 in self.model:
total_count = float(sum(self.model[w1].values()))
denominator = total_count + self.alpha * len(self.vocab)
for w2 in self.model[w1]:
self.model[w1][w2] /= total_count
self.model[w1][w2] = (self.model[w1][w2] + self.alpha) / (
total_count + self.alpha * len(self.vocab)
)
nominator = self.model[w1][w2] + self.alpha
self.model[w1][w2] = nominator / denominator
def _predict(self, word):
predictions = dict(self.model[word])
most_common = dict(Counter(predictions).most_common(5))
most_common = dict(Counter(predictions).most_common(6))
total_prob = 0.0
str_prediction = ""

File diff suppressed because it is too large Load Diff