NoneType' object has no attribute 'shape'

so this is my code

sentence = tokenize(sentence)
X = bag_of_words(sentence,all_words)
X = X.reshape(1,X.shape[0])
X = torch.from_numpy(X).to(device)

and this is the error given
AttributeError: ‘NoneType’ object has no attribute ‘shape’

what is bag_of_words

Its basically a neural network function…

def bag_of_words(tokenized_sentence,words):
sentence_words = [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

the code for bag of words

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)