You’ve made what is probably the most common mistake on this function. When you count the positive and negative frequencies, you simply add 1 for each occurrence of a given word. What was intended was that you would add the actual frequency from the freqs dictionary for that.