I have had all the test cases passed apart from one, can someone please guide?
You can see that âsuggestionsâ should be a dictionary a set - {âdaysâ, dyeâ},
not a list - [âdaysâ, âdyeâ] (as in your picture).
Cheers
Did you mean set and not dictionary?
Thank you for correcting me - it should have been a set not a dictionary. ![]()
Try restarting the kernel, because the environment might have cashed your previous function.
Cheers
The output as you can see is updated and the result is what we expected. But the test function is still not passing.
The output could have been updated but the function passed to the unit test could have been cached. In any case, the kernel restart could clear that possibility.
However, I looked into unit test code. It has the wrong exception string - it checks for length (with len(result )) but reports the âWrong output typeâ. So, you should check that you return the expected output:
Output:
n_best: a list of tuples with the most probable n corrected words and their probabilities.
Cheers
Restarted the Kernel and it does not appear to solve the problem. I am returning the output as the list of tuples as it is mentioned in the assignment.
However, cannot understand what I am doing wrong here.
Could you give me an example case where the code could be going wrong? I do not want the unit test code being used in the assignment but something similar, testing which can help me debug the problem. I have gone over my solution a few times but cannot seem to wrap my head around it. Further guidance will be much appreciated.
Ok, here is step by step what you can check:
Step 1: Generate suggestions for a supplied word: Youâll use the edit functions you have developed. The âsuggestion algorithmâ should follow this logic:
#Step 1: create suggestions as described above
# ... your solution
print(suggestions) # would result in: {'dye', 'days'}
# type(suggestions) -> <class 'set'>
Step 2: Create a âbest_wordsâ dictionary where the âkeyâ is a suggestion and the âvalueâ is the probability of that word in your vocabulary. If the word is not in the vocabulary, assign it a probability of 0.
#Step 2: determine probability of suggestions
# ... your solution
print(best_words) # would result in: {'dye': 1.865184466743761e-05, 'days': 0.0004103405826836274}
# type(best_words) -> <class 'dict'>
Step 3: Select the n best suggestions. There may be fewer than n.
#Step 3: Get all your best words and return the most probable top n_suggested words as n_best
# ... your solution
print(n_best) # would result in: [('days', 0.0004103405826836274), ('dye', 1.865184466743761e-05)]
# type(n_best) -> <class 'list'>
Cheers
I am afraid these are not helpful. These are just the steps mentioned in the assignment itself. Please understand that I have got most of the test cases correct and doing some mistake at a very particular place and not in the whole thing. Will really appreciate if you could guide being a little bit more specific about what I might be doing wrong.
Out of 9 test cases, 8 are correct that means I must be returning things correctly.
Right before this cell :
# Test your function
w1_unittest.test_get_corrections(get_corrections, probs, vocab)
Does print(tmp_corrections) result in:
[('days', 0.0004103405826836274), ('dye', 1.865184466743761e-05)]
?


