udacity / deep-learning-v2-pytorch

Projects and exercises for the latest Deep Learning ND program https://www.udacity.com/course/deep-learning-nanodegree--nd101
MIT License
5.27k stars 5.32k forks source link

Fixing Key error in predict #272

Closed sudhanshu456 closed 3 years ago

sudhanshu456 commented 4 years ago

Due to some words are not present in the dictionary of words that cause a problem of key error if we try to use it any other example :


test_review_neg = " Ice-Cubes character is a bit forced, but it has some appealing moments." ```  in this "Icecube" lead to Key error because this is not present in the model while adding a dictionary so to held this there was no code.

I change  to "test_ints.append([vocab_to_int.get(word, 0) for word in test_words])"
 from "test_ints.append([vocab_to_int[word] for word in test_words])"

this solve the Key error if somebody wants to try out with any other example