Given a text corpus, compute the unigram probability of each word. The unigram probability of a word is its frequency count divided by the total number of words in the corpus.
def unigram_probabilities(corpus: list[str]) -> dict[str, float]:
word_counts: dict[str, int] = {}
total = 0
for sentence in corpus:
words = sentence.lower().split()
for word in words:
word_counts[word] = word_counts.get(word, 0) + 1
total += 1
return {word: count / total for word, count in word_counts.items()}