I've been learning about Python AI, and finally came around to actually making one, but for some reason, I keep getting the following error after running the main chatbot file and typing in an input:
Traceback (most recent call last):
File "d:\Users\DagerTCD\OneDrive\Monuta - v1.10 MVI\cb.py", line 56, in <module>
ints = predict_class(message, model)
File "d:\Users\DagerTCD\OneDrive\Monuta - v1.10 MVI\cb.py", line 34, in predict_class
res = model.predict(np.array([bow]))[0]
File "C:\Users\DagerTCD\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1743, in predict
tmp_batch_outputs = self.predict_function(iterator)
File "C:\Users\DagerTCD\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\DagerTCD\AppData\Local\Programs\Python\Python310\lib\site-packages\tensorflow\python\framework\func_graph.py", line 1147, in autograph_handler
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:
ValueError: Input 0 of layer sequential_2 is incompatible with the
layer: expected axis -1 of input shape to have value 4 but received
input with shape (None, 19)
I know it's a value error and that I should reshape the value of my input, but whenever I try to do so, all I get is an error stating that I can't reshape the value to 4. I tried searching online, but I can't find any solutions or questions related to my problem. Could someone look over and/or explain what's wrong with my code, if that's alright...? More specifically, the Sequential Model part of the code, because I'm assuming there's something wrong there, considering that related problems seem to have issues here.
model = Sequential()
model.add(Dense(64, input_shape=(len(train_x[0]),), activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(len(train_y[0]), activation='softmax'))
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
hist = model.fit(np.array(train_x), np.array(train_y), epochs=88, batch_size=5, verbose=1)
model.save('monutamodel.h5', hist)
print("Training Completed")
Here is the training variable code or whatever, in case it may be useful in helping...
training.append([bag, output_row])
random.shuffle(training)
training = np.array(training)
train_x = list(training[:, 0])
train_y = list(training[:, 1])
Just in case, here's a link to the 3 files used for the code, all on google drive
{Any tips, in general, are helpful and appreciated! If there is anything wrong with this post, please give me some feedback!}
Edit:
I tried printing train_y, but I just got:
[[0, 0, 0, 1]]
as the result. I then tried reshaping it using:
model.add(Reshape((4,), input_shape=(train_y)))
but it just stayed the same and still shows the same error?