An implementation of N-gram language modeling with Kneser-Ney smoothingin Python3.
chapter = ""
with open ('Austen_Pride.txt','r') as f:
for line in f:
chapter += line
chapter = chapter.replace('\n', ' ').replace("", "").strip("'").strip("`")
import KneyserNey
ngram_order = 3
prideKN = kneyserNey()
prideKN.fit(chapter, ngram_order)
phrase='truth universally hated'
d = 0.75 #the discounting factor
prideKN.score(phrase, ngram_order, d)