fig = pyplot.gcf() fig.set_size_inches(20, 15) ax1 = fig.add_subplot(211) ax1.set_ylabel('L_m') ax1.set_xlabel('Values of Lambda') pyplot.plot(alpha, result) pyplot.show() if __name__ == "__main__": # read all required files from FileReader import FileReader file = FileReader() vocab, unigram, bigram = file.readAll() # compute the probability of each word from LanguageModel import LanguageModel lm = LanguageModel() P_w = lm.Unigram(unigram) vocab_size = len(vocab) P_w1_w2, words = lm.Bigram(bigram, vocab_size) sentence = 'The sixteen officials sold fire insurance' word_list = sentence.upper().split() # calculate log-likelihood under unigram result_unigram = log_likelihood_unigram(word_list, P_w, vocab) print("Log-likelihood under unigram model is " + str(math.log(result_unigram)))