NeuralNine / neuralintents

A simple interface for working with intents and chatbots.
MIT License
249 stars 135 forks source link

Virtual Assistant Training Error #40

Closed ghost closed 1 year ago

ghost commented 1 year ago

When I start the program, it gives me these syntax errors:

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. training = np.array(training) WARNING:absl:lr is deprecated in Keras optimizer, please use learning_rate or use the legacy optimizer, e.g.,tf.keras.optimizers.legacy.SGD. Traceback (most recent call last): File "sensitive info", line 113, in assistant.train_model() File "sensitive info", line 109, in train_model sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "sensitive info", line 111, in init super().init( File "sensitive info", line 1087, in init super().init( File "sensitive info", line 105, in init self._process_kwargs(kwargs) File "sensitive info", line 134, in _process_kwargs raise ValueError( ValueError: decay is deprecated in the new Keras optimizer, pleasecheck the docstring for valid arguments, or use the legacy optimizer, e.g., tf.keras.optimizers.legacy.SGD.

These errors have been reported many times by people. Please kindly fix this issue.

Sincerely, ExpertCoder101

ghost commented 1 year ago

Also, here is my code. If there is anything wrong, that might be the solution to my problem.

from neuralintents import GenericAssistant import speech_recognition import pyttsx3 as tts import sys

recognizer = speech_recognition.Recognizer()

speaker = tts.init() speaker.setProperty('rate', 150)

todo_list = []

def create_note(): global recognizer

speaker.say("What do you want to write on your note?")
speaker.runAndWait()

done = False

while not done:
    try:

        with speech_recognition.Microphone() as mic:

            recognizer.adjust_for_ambient_noise(mic, duration=0.2)
            audio = recognizer.listen(mic)

            note = recognizer.recognize_google(audio)
            note = note.lower()

            speaker.say("Choose a filename!")
            speaker.runAndWait()

            recognizer.adjust_for_ambient_noise(mic, duration=0.2)
            audio = recognizer.listen(mic)

            filename = recognizer.recognize_google(audio)
            filename = filename.lower()

        with open(f"{filename}.txt", 'w') as f:
            f.write(note)
            done = True
            speaker.say(f"I successfully created the note {filename}")
            speaker.runAndWait()
    except speech_recognition.UnknownValueError:
        recognizer = speech_recognition.Recognizer()
        speaker.say("I did not understand you! Please try again!")
        speaker.runAndWait()

def add_todo(): global recognizer

speaker.say("What to do do you want to add?")
speaker.runAndWait()

done = False

while not done:
    try:

        with speech_recognition.Microphone() as mic:

            recognizer.adjust_for_ambient_noise(mic, duration=0.2)
            audio = recognizer.listen(mic)

            item = recognizer.recognize_google(audio)
            item = item.lower()

            todo_list.append(item)
            done = True

            speaker.say(f"I added {item} to the to do list!")
            speaker.runAndWait()

    except speech_recognition.UnknownValueError:
        recognizer = speech_recognition.Recognizer()
        speaker.say("I did not understand. Please try again!")
        speaker.runAndWait()

def show_todos():

speaker.say("The items on your to do list are the following")
for item in todo_list:
    speaker.say(item)
speaker.runAndWait()

def hello(): speaker.say("Hello, what can I do for you?") speaker.runAndWait()

def quit(): speaker.say('Bye') speaker.runAndWait() sys.exit(0)

mappings = { "greeting": hello, "create_note": create_note, "add_todo": add_todo, "show_todos": show_todos, "exit": quit }

assistant = GenericAssistant('intents.json', intent_methods=mappings) assistant.train_model()

while True:

try:
    with speech_recognition.Microphone() as mic:

        recognizer.adjust_for_ambient_noise(mic, duration=0.2)
        audio = recognizer.listen(mic)

        message = recognizer.recognize_google(audio)
        message = message.lower()

    assistant.request(message)
except speech_recognition.UnknownValueError:
    recognizer = speech_recognition.Recognizer()
ghost commented 1 year ago

If you want to fix this problem, you have to go to the main.py file given in the traceback. Then, you need to go to line 109. After that, delete the decay argument. This should fix your problem, and it should work.