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