Hello there guys. First time making a post here.
So I am trying to make an AI chatbot using Python, in a Pycharm IDLE. While trying to start training the neural network that would enable the chatbot to work, I ran into this error and was unable to find any resources I could use to help me solve this:
Traceback (most recent call last):ie the code where the error occured
sgd = gradient_descent_v2.SGD(learning_rate=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimiser=sgd, metrics=['accuracy'])
I also had to import SGD like this because otherwise it couldn't be found:
from keras.optimizers import gradient_descent_v2
If anybody knows how to solve this, please tell me!
This is my first ever post too.
The problem is:
model.compile(loss='categorical_crossentropy', optimiser=sgd, metrics=['accuracy'])
The order of arguments should be changed. And the sgd
should be included in single quotes. Also, the optimiser
should be optimizer
with a z.
So it should look like this:
model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy'])
Also, in regard to importing, try this:
from tensorflow.keras.optimizers import SGD
And make sure you imported the categorical_crossentropy before.
A helpful document from keras website:
https://www.tensorflow.org/api_docs/python/tf/keras/Model. And here you could find 30 examples that might be helpful: https://www.programcreek.com/python/example/97109/keras.losses.categorical_crossentropy.
Good luck with your project!