import numpy as np import tensorflow from tensorflow import keras from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Dropout, Activation from tensorflow.keras.layers import Conv2D, MaxPooling2D from tensorflow.keras.preprocessing.text import Tokenizer # words pizza = [1,0,0,0,0,0] taco = [0,1,0,0,0,0] sushi = [0,0,1,0,0,0] car = [0,0,0,1,0,0] bike = [0,0,0,0,1,0] truck = [0,0,0,0,0,1] #Training data sentence1 = "I like pizza, taco and sushi" classonevalues = [pizza,taco,sushi] sentence2 = "I have a car, bike and a truck" classtwovalues = [car,bike,truck] x_train = np.array(classonevalues+classtwovalues) y_train = np.array([[1,0],[1,0],[1,0],[0,1],[0,1],[0,1]]) print(x_train) print(y_train) max_words = 6 num_classes = 2 batch_size = 1 epochs = 5 #Model model = Sequential() model.add(Dense(256, input_shape=(max_words,))) model.add(Activation('relu')) model.add(Dense(2)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, verbose=1, validation_split=0) sentence_test1 = "I like pizza, taco and sushi" sentence_test1_vector = [1,1,1,0,0,0] sentence_test2 = "I have a car, bike and a truck" sentence_test2_vector = [0,0,0,1,1,1] def classify(vector): aindex = np.argmax(model.predict(np.array([vector]))) if(aindex==0): print("Food") else: print("Cars") classify(sentence_test1_vector) classify(sentence_test2_vector)