From the message it looks like your dictionary lookup index has the value of the character i, but i is supposed to be an integer with value of 2.
(Also looks like your vocabulary is the wrong size)
Yes,sir what changes should I need to do??
To address the KeyError, you need to understand first what one is:
exception KeyError (Built-in Exceptions — Python 3.11.1 documentation)
Raised when a mapping (dictionary) key is not found in the set of existing keys.
Python is flexible when it comes to dictionary keys, but in this case It needs to be an integer between 0 and the size of word_index. So one thing to check is how the key-value pairs are bing added to your index.That might reveal the issue in vocab size. Then, look at how the variable i is being assigned a value; make sure it is a number that is an acceptable key for the word_index dictionary.
If this doesn’t make sense, you may need to level up your Python skills or this course is going to be frustrating.
So 1) getting other people to debug basic language trouble in your code isn’t really how this forum is supposed to work. But 2) it looks like there is still some confusion about strings, arrays, indices etc since I notice it in another thread you posted. I’m going to give the same advice you got there, and above, which is try to gain more knowledge on Python data structures and how to manipulate them before trying to use them in machine learning or other applications. Cheers