Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week1 Assignment # UNQ_C10 GRADED FUNCTION #3

Open
SajjadPSavoji opened this issue Dec 5, 2022 · 0 comments
Open

Week1 Assignment # UNQ_C10 GRADED FUNCTION #3

SajjadPSavoji opened this issue Dec 5, 2022 · 0 comments

Comments

@SajjadPSavoji
Copy link

December 2022, I had to change the following function to pass all test cases

`# UNQ_C10 GRADED FUNCTION: get_corrections
def get_corrections(word, probs, vocab, n=2, verbose = False):
'''
Input:
word: a user entered string to check for suggestions
probs: a dictionary that maps each word to its probability in the corpus
vocab: a set containing all the vocabulary
n: number of possible word corrections you want returned in the dictionary
Output:
n_best: a list of tuples with the most probable n corrected words and their probabilities.
'''

suggestions = []
n_best = []

### START CODE HERE ###
#Step 1: create suggestions as described above    
suggestions = list((word in vocab and word) or edit_one_letter(word).intersection(vocab) or edit_two_letters(word).intersection(vocab))
n_best = [[s,probs[s]] for s in list(reversed(suggestions))]
n_best = sorted(n_best, key=lambda x: x[1])[::-1][:n]
### END CODE HERE ###

if verbose: print("entered word = ", word, "\nsuggestions = ", suggestions)

return n_best`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant