i did not get this error
sentence='i am going to school'
vocab=['i','go','there','he','she','it','college','school']

import nltk
from nltk.stem.porter import PorterStemmer
stemmer=PorterStemmer()

def tokenize(sentence):
    return sentence.split()

def bag_of_words(tokenized_sentence,words):
    sentence_words = [stemmer.stem(word) for word in tokenized_sentence]
    bag = np.zeros(len(words),dtype=np.float32)

    for idx , w in enumerate(words):
        if w in sentence_words:
            bag[idx] = 1
    return bag

sentence = tokenize(sentence)
X = bag_of_words(sentence,vocab)
print(X)