Question: Please help to fix my error and only change the code under #your code here. I've also included a screenshot of the error shown. Traceback

Please help to fix my error and only change the code under #your code here.
I've also included a screenshot of the error shown.
Traceback (most recent call last)
Problem 2: Using a Bloom Filter to Count Common Words.
In this problem, we will implement a Bloom filter to count how many elements of longer_words_wp (the words of length 5 or more in War and Peace)
appear in the Great-Gatsby novel. To do so, we will do the following:
Instantiate a Bloom filter with number of bits n and number of hash functions k.
Insert all words from great-gatsby into the filter.
For each word from war and peace, check membership in the Bloom filter and count the number of yes answers.import hashlib
class BloomFilter: self.bits =[False]*nbits # Initialize all bits to fals self.k = nhash self.hash_fun_reps =[get_random_hash_function() for i in range(self.k)] seed = random.randint (0, self.m -1)# Function to insert a word in a Bloom filter. # your code here index = hash_fun(word)# Check if a word belongs to the Bloom Filter # your code here index = hash_fun (word) return FalseIn [10]:
#do the exact countthis operation finishes very quickly.
all_words_gg = set(longer_words_gg)
exact_common_wc =0
for word in longer_words_wp: exact_common_wc = exact_common_wc +1
print(f'Exact common word count ={exact_common_wc}')
Exact common word count =124595
In [11]: # Try to use the same using a bloom filter.for word in longer_words_gg:for word in longer_words_gg:common_word_count =0 if bf.member(word):print(f'Number of common words of length >=5 equals : {common_word_count}')print('All Tests Passed: 10 points')
 Please help to fix my error and only change the code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!