Code QuizIntermediate Term Frequency Wrong Denominator
Find the mistake in how term frequency is normalized.
Codepython
def term_frequency(tokens):
counts = {}
for t in tokens:
counts[t] = counts.get(t, 0) + 1
tf = {}
for t in counts:
tf[t] = counts[t] / len(counts)
return tf
print(term_frequency(['a', 'a', 'b']))What is the bug in this term frequency computation?