Implement a function that calculates the unigram probability of a given word in a corpus of sentences. Include start <s> and end </s> tokens in the calculation. The probability should be rounded to 4 decimal places.
Examples
Example 1:
Input:
corpus = "<s> Jack I like </s> <s> Jack I do like </s>", word = "Jack"Output:
0.1818Explanation: The corpus has 11 total tokens. 'Jack' appears twice. So, probability = 2 / 11
Starter Code
def unigram_probability(corpus: str, word: str) -> float:
# Your code here
passPython3
ReadyLines: 1Characters: 0
Ready