If you are dealing with unknown words, you could add a specific word index for these unknown words and change the indexesFromSequence method a bit to yield it as the default value:
def indexesFromSentence(lang, sentence):
    unknown_index = 0
    return [lang.word2index.get(word, unknown_index) for word in sentence.split(' ')]

Note that you would most likely have to adapt some other code parts to deal with this unknown index.