A bit old now, here is some updated code for anyone watching. import random import json import pickle import numpy as np import tensorflow as tf import nltk from nltk.stem import WordNetLemmatizer lemmatizer = WordNetLemmatizer() intents = json.loads(open('intents.json').read()) words = [] classes = [] documents = [] ignoreLetters = ['?', '!', '.', ','] for intent in intents['intents']: for pattern in intent['patterns']: wordList = nltk.word_tokenize(pattern) words.extend(wordList) documents.append((wordList, intent['tag'])) if intent['tag'] not in classes: classes.append(intent['tag']) words = [lemmatizer.lemmatize(word) for word in words if word not in ignoreLetters] words = sorted(set(words)) classes = sorted(set(classes)) pickle.dump(words, open('words.pkl', 'wb')) pickle.dump(classes, open('classes.pkl', 'wb')) training = [] outputEmpty = [0] * len(classes) for document in documents: bag = [] wordPatterns = document[0] wordPatterns = [lemmatizer.lemmatize(word.lower()) for word in wordPatterns] for word in words: bag.append(1) if word in wordPatterns else bag.append(0) outputRow = list(outputEmpty) outputRow[classes.index(document[1])] = 1 training.append(bag + outputRow) random.shuffle(training) training = np.array(training) trainX = training[:, :len(words)] trainY = training[:, len(words):] model = tf.keras.Sequential() model.add(tf.keras.layers.Dense(128, input_shape=(len(trainX[0]),), activation = 'relu')) model.add(tf.keras.layers.Dropout(0.5)) model.add(tf.keras.layers.Dense(64, activation = 'relu')) model.add(tf.keras.layers.Dropout(0.5)) model.add(tf.keras.layers.Dense(len(trainY[0]), activation='softmax')) sgd = tf.keras.optimizers.SGD(learning_rate=0.01, momentum=0.9, nesterov=True) model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy']) model.fit(trainX, trainY, epochs=200, batch_size=5, verbose=1) model.save('chatbot_model.h5') print('Done')
A much-needed updated vision of the chatbot from Tech with Tim. Love this video. From a viewer standpoint and someone who is coding along with you to program this thing. Either don't put a video of yourself on the screen, put it in the upper right-hand corner, or make it smaller. It's hard to code along with you as the camera of yourself blocks some of your code in the video.
Man, you are so underrated. I always search for simple examples of complex topics. After looking at your videos I am able to implement the basics in my projects easily
🎯 Key Takeaways for quick navigation: 00:04 *🤖 Setting up the intense.json file for the chatbot* - Creating an intense.json file to categorize user inputs for the chatbot. - Defining categories such as greetings, questions about prices, and goodbyes. - Specifying patterns and static responses for each category to train the chatbot. 06:12 *💻 Coding the chatbot in Python* - Importing necessary libraries including random, json, pickle, numpy, and nltk. - Lemmatizing words to reduce them to their base form for better performance. - Processing the intense.json file to prepare training data for the chatbot. 19:08 *🧠 Building the neural network model* - Shuffling and converting training data into numpy arrays for features and labels. - Creating a sequential model and adding layers including input, dense, and dropout layers. - Using rectified linear unit (ReLU) activation function and stochastic gradient descent (SGD) optimizer for training. 20:46 *🧠 Building the Neural Network Model* - Building a neural network model for the chatbot. - Adding dense layers with specified neurons and activation functions. - Defining optimizer parameters and compiling the model. 24:12 *💬 Setting up Chatbot Application* - Setting up the chatbot application to use the trained model. - Importing necessary libraries and loading the trained model. - Defining functions for processing user input and generating responses. 27:05 *🧹 Cleaning and Preparing Input Data* - Defining functions for cleaning up sentences and converting them into bags of words. - Preprocessing input data to prepare it for prediction by the neural network. - Ensuring that the input data format aligns with the model's requirements. 29:38 *🤖 Predicting Classes and Generating Responses* - Implementing a function to predict classes based on input sentences using the model. - Establishing a threshold for accepting predictions to manage uncertainty. - Generating responses based on predicted classes and probabilities. Made with HARPA AI
? - keras in "tensorflow.keras..." is not recognized by 'Pycharm', but it works anyway. Changes: - from tensorflow.keras.optimizers import SGD + from tensorflow.keras.optimizers.legacy import SGD - training = np.array(training) +training = np.array(training, dtype=object) -sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) +sgd = SGD(learning_rate=0.01, decay=1e-6, momentum=0.9, nesterov=True)
The video got really good but we don’t really clarify what packages to download. I know you said what at the beginning at Imports but it still gives me error messages with Tensorflow. For example: ' To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. '
So...as far as the machine learning goes, it's just a text classification algorithm. I would love to see a version of this with actual text generation as well!
when it comes to trading in the various financial markets the relevance of professional guidance should not be undervalued as it could be the key to any traders success in profit making
@@piricontes2844 I will highly recommend Michael Branagh, he helped me secure a passive source of income, made life quiet easier for me as I no longer had to work round the clock. I'd check if he's taking new investors now, and also ask if I can share his contact information to the public.
@@JacobHKent i have stumbled upon a couple of articles by him, never occured to me to look him up. i would sincerely appreciated if you coild help with his contact info.
@@JacobHKent Mr Branagh is one of the most productive traders out there. i would not say hes the best at what he does but one thing is certain, hes a man of integrity and he certaainly gets results
you'd just use discord.py to detect when a message is sent, use that message as the input for the AI, and output the AI's output as the discord message
if you get an error with hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size =5, verbose=1 ), just delete "accuracy in model.compile
NIce video! Can you make an in-depth tutorial on making a friend-like chatbot that uses neural networks and NLP, and adapts it to modern libraries like Keras and TensorFlow? I've been making a project, but I've been having some issues.
Nice tutorial on basic Keras NN setup. The truth is there is no need for a NN here. What it does is a simple input text selector and a random generator to output the response text. You could do the same using regexp/similar text/soundex word matching.
Please put more videos like this bro, I needed some sorry more.... And if you are about to launch a video give a gif for that. That thrill will be enough for me to be happy. Don't get faded bro, we need you...
for intent in intents['intents']: for pattern in intent['patterns']: word_list = nltk.word_tokenize(pattern) words.append(word_list) documents.append((word_list, intent['tag'])) if intent['tag'] not in classes: classes.append(intent['tag']) This showing me error " For pattern in intent['patterns'] KeyError : 'patterns' Please help me out!
when i finished this chat i typed in terminal: " hello!" the answer was "sad to see you go :( " hahahahahahah i'm crying !!!! thank you it's working perfectly
@@fernandobarocio2796 He used the intention.py file to answer the users. so you can use your own file or just google it you can find a lot of them. it's not a big problem. good luck.
training = np.array(training) throws an error! ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (12, 2) + inhomogeneous part.
Sorry if it's too late, but I solved this error with the following: training_array = [] for item in training: part1 = np.array(item[0]) part2 = np.array(item[-1]) list_items = [part1, part2] training_array.append(list_items) Then you can use 'training_array' np.array(training) like.
Hi NeuralNine, this is a great piece. I would like to ask you if this tutorial would work for another language. Would it be enough to just edit intents, to comply with the language I would like to use? And the second question, do you have some tutorial, on how to implement this bot to streamlabs chatbot for twitch?
#Dec 2023- import random import json import numpy as np import pickle import tensorflow as tf import nltk from nltk.stem import WordNetLemmatizer from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Activation, Dropout from tensorflow.keras.optimizers import SGD from tensorflow.keras.preprocessing.sequence import pad_sequences # Download NLTK data nltk.download('punkt') nltk.download('wordnet') lemmatizer = WordNetLemmatizer() intents = json.loads(open('intents.json').read()) words = [] classes = [] documents = [] ignore_letters = ['?', ',', '!', '.'] for intent in intents['intents']: for pattern in intent['patterns']: word_list = nltk.word_tokenize(pattern) documents.append((word_list, intent['tag'])) words.extend(word_list) # Append words to the 'words' list if intent['tag'] not in classes: classes.append(intent['tag']) words = [lemmatizer.lemmatize(word.lower()) for word in words if word not in ignore_letters] words = sorted(set(words)) classes = sorted(set(classes)) pickle.dump(words, open('words.pkl', 'wb')) pickle.dump(classes, open('classes.pkl', 'wb')) training = [] output_empty = [0] * len(classes) for document in documents: bag = [] word_patterns = document[0] word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns] # Create a bag of words with 1s and 0s bag = [1 if word in word_patterns else 0 for word in words] # Create the output row output_row = list(output_empty) output_row[classes.index(document[1])] = 1 # Append the bag and output_row as separate lists training.append([bag, output_row]) # Shuffle the training data random.shuffle(training) # Split the training data into X and Y train_x = np.array([item[0] for item in training]) train_y = np.array([item[1] for item in training]) model = Sequential() model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu')) model.add(Dropout(0.5)) model.add(Dense(64, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(len(train_y[0]), activation='softmax')) sgd = SGD(learning_rate=0.01, momentum=0.9, nesterov=True) model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy']) hist = model.fit(train_x, train_y, epochs=200, batch_size=5, verbose=1) model.save('Chatbot_model.h5', hist) print("Done!")
What in the world! Thankfully I found you and now I trained my model correctly. I was getting this error: 78 random.shuffle(training) ---> 79 training = np.array(training) 80 81 train_x = list(training[:, 0]) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (392, 2) + inhomogeneous part. I don't know what to do with this I asked every gpts even got link of source code in github then also getting same error. I just copied your code and hit run and then thankfully it worked.
Hey NeuralNine, really like the videos. Could you please like zoom in to the code... Or like increase the font. Its kinda difficult to see the code especially when not on full screen. Even when youre showing other stuff like how to install mingw for c++... The text looks really small But i really love your content and learn a lot. So if you could address that i'd be stoked
Awesome work bro! I like your videos Kudos to you I suggest you make a tutorial video on show to deploy an AI CHATBOT to back-end server to improve responsiveness and present more details.
When I added training data to the intents.json file, I got this error, anybody who can help? ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 38 but received input with shape (None, 84) I figured out that the 84 is just the amount of patterns in the intents.json file, but I haven't figured out why the input shape has to have a value of 38.
Traceback (most recent call last): File "E:/CODEING/lapsever/test.py", line 20, in model = load_model("chatbotmodel.h5") File "C:\Users\Mr.Programmer\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile) File "C:\Users\Mr.Programmer\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 166, in load_model_from_hdf5 model_config = json.loads(model_config.decode('utf-8')) AttributeError: 'str' object has no attribute 'decode' error
Well, I followed along and as I ran it....this guy decided to reply "Hello" with "Talk to you later" LMAOO 😭Even a bot isnt interested in talking with me 😒
training = np.array(training) is returning an error, can you help? --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[24], line 26 24 # shuffle our features and turn into np.array 25 random.shuffle(training) ---> 26 training = np.array(training) 28 # create train and test lists. X - patterns, Y - intents 29 train_x = list(training[:, 0]) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (27, 2) + inhomogeneous part.
If there’s nothing wrong with the preprocessing you probably have to find a way to properly tune the model with a test set and a training set to prevent under or overfitting.
If you guys keep getting goodbye messages for other things change the error_threshold to 0.5 and if that doesn't work change the epochs in training.py to 800
Works great! Im having this error when adding more than 3 intents though. ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 27 but received input with shape [None, 30]. :/
I was recieving TypeError at 14:30 This solve for me " pip install self nltk.download('wordnet') import self words = [lemmatizer.lemmatize(self, word) for word in words if word not in ignore_letters] words = sorted(set(words)) "
22:08 Hi, i'm new to DL.. When we use Softmax, if there are (say)two outputs in the network, it will output probabilities like [.4 ,.6] or [.1, .9] or [.5, .5] etc right? (sum always 1).. so even if we enter some gibberish as input, there will always be some output(s) above error threshold of (say) .25. How ill I tweak this so this won't happen? ( i mean if i enter "ahfliehf fsdlihfasdh" to bot, the outputs should be like something like [0.001, 0.00123])
Hello... i have tried to copy your code now in 2023 and apparently there is an issue with training = np.array(training) since the [bag, output_row] columns don't have the same dimensions (maybe I have copied something wrong along the way...). I have came up with a solution that bypass the issue, although its quite a caveman style solution and I do not have the knowledge to understand its consequences, but it does not crash the code and allows me to train the chatbot. solution: when defining the dimensions of: output_empty = [0] * len(classes) instead do: output_empty = [0] * len(words) this way the dimensions of "bag" and "output_row" are the same. (It will fill the space with 0, so it shouldn't change the bot training accuracy... but what do I know :D )
@@Kanishkaran.__ Not really sure, but as I figured lately its quite a lot about version compatibilities with TF and all these days. Try searching if your versions match.
Hey, any idea how you'd get this to run with tflite? Edit: Okay, I've gotten the model to run, but I realised nltk stemming is really slow. Is there a faster alternative? (actually I'll try figure out exactly what's taking ages) Edit #2: Nevermind, it all works, there's just a delay the first time the process is called for some reason (Which I'll try to trace and fix) Thanks for the great tutorial, can't wait to setup my own personal assistant!
@@ratto751 I was using 3.8 and I had the same issue as this guy so I looked it up, read an article that told me tensorflow doesn't work beyond 3.6.4 so I switched versions and it completely fixed my issue. So if you really insist that my experience was purely circumstantial
@@maxmayer3551 Would you rather trust an article or the official TensorFlow GitHub and PyPi? I've been able to run TensorFlow on python 3.8. There must be some other problem with your PC since it works with 3.8 on mine.
I'm trying to create a chatbot for customer care, it is going to be a live support agent for industries like Telecom companies, so after I finish with all the knowledge you have shared maybe I will have some questions and everything else.
I learned a lot through this video. However since we have static replies for this exact project I believe that splitting the string from the user input into a list as you did, finding a key word and thus give the reply could be easily and faster done with if else statements. I get the educational manner for the AI part but because you didn’t exactly analyze the code that you used in the machine learning part because of the purpose of the video I will stick to my opinion having the thought of the purpose of the video being “build a chatbot” and not “use ai to create something”. Great video though❤
Hello, just wanted to throw my feedback for you guys! Very good video (you should watch his neural network theory video, it helps a lot) While implementing alongside you I would always get no more than 0.75 accuracy, BUT if for the first time we use lemmatize you put this: words = [lemmatizer.lemmatize(word.lower()) for word in words if word not in symbols_to_ignore] It increases the accurasy to 0.9 - 1. Which makes the AI much more efficient! Also in the cleaning up sentence fuction you might want to make the sentence lower cased :)
men thank you for this totoriol, i download your video , creat ai chat bot ful system you show me many things i don't know her you are amazing thank you
A bit old now, here is some updated code for anyone watching.
import random
import json
import pickle
import numpy as np
import tensorflow as tf
import nltk
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
intents = json.loads(open('intents.json').read())
words = []
classes = []
documents = []
ignoreLetters = ['?', '!', '.', ',']
for intent in intents['intents']:
for pattern in intent['patterns']:
wordList = nltk.word_tokenize(pattern)
words.extend(wordList)
documents.append((wordList, intent['tag']))
if intent['tag'] not in classes:
classes.append(intent['tag'])
words = [lemmatizer.lemmatize(word) for word in words if word not in ignoreLetters]
words = sorted(set(words))
classes = sorted(set(classes))
pickle.dump(words, open('words.pkl', 'wb'))
pickle.dump(classes, open('classes.pkl', 'wb'))
training = []
outputEmpty = [0] * len(classes)
for document in documents:
bag = []
wordPatterns = document[0]
wordPatterns = [lemmatizer.lemmatize(word.lower()) for word in wordPatterns]
for word in words:
bag.append(1) if word in wordPatterns else bag.append(0)
outputRow = list(outputEmpty)
outputRow[classes.index(document[1])] = 1
training.append(bag + outputRow)
random.shuffle(training)
training = np.array(training)
trainX = training[:, :len(words)]
trainY = training[:, len(words):]
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(128, input_shape=(len(trainX[0]),), activation = 'relu'))
model.add(tf.keras.layers.Dropout(0.5))
model.add(tf.keras.layers.Dense(64, activation = 'relu'))
model.add(tf.keras.layers.Dropout(0.5))
model.add(tf.keras.layers.Dense(len(trainY[0]), activation='softmax'))
sgd = tf.keras.optimizers.SGD(learning_rate=0.01, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
model.fit(trainX, trainY, epochs=200, batch_size=5, verbose=1)
model.save('chatbot_model.h5')
print('Done')
man you just saved my code by changing words.append to words.extend
tyvm bro
Thank you
thaks bro
trainX = training[:, :len(words)]
trainY = training[:, len(words):]
oh my god thank you so much now it works
sike bro
Man, you are THE ONLY ONE explaining this intent type of neural net-based chatbot. Thanks a lot
Instructions unclear, made Ultron. 😂
😂 this had me laughing way more than I expected lol
same😅
😂😂😂😂
Instructions Unclear for me too, made big piece of unusable crap code taking up space on my computer.
Awesome content! when are we getting the biceps tutorial tho?
Some day maybe😂😂
@@NeuralNine i am am i am iam
the chat bot said that idk what im doing
@@fortniteawesomeparadys6242 It's becoming self aware. "I AM!"
Oh God. I need that tutorial ❤️
A much-needed updated vision of the chatbot from Tech with Tim. Love this video. From a viewer standpoint and someone who is coding along with you to program this thing. Either don't put a video of yourself on the screen, put it in the upper right-hand corner, or make it smaller. It's hard to code along with you as the camera of yourself blocks some of your code in the video.
This video is more explanatory and far better than the tech tim video, and the tech tim guy was just rushing,
question, what kind of neural network architecture used here? Is it RNN?
@@tomcat9761 No. It's a simple ANN
hey. where can i get source code? any idea?
try watching the video
Videos on neural network theory would be fantastic! Thanks again for another great video!
question, what kind of neural network architecture used here? Is it RNN?
@@tomcat9761 i don't know
@@tomcat9761 its ANN
Man, you are so underrated. I always search for simple examples of complex topics. After looking at your videos I am able to implement the basics in my projects easily
ruclips.net/channel/UC0Bn9e36XqiiNZp9ClkPUww
hey. where can i get source code? any idea?
type it, lmao. @@mahnoorhome
I never opened a RUclips notification so fast
hahahaha thank you :)
Same
same
ruclips.net/channel/UC0Bn9e36XqiiNZp9ClkPUww
@@vipulkumar9858 why this comment??
🎯 Key Takeaways for quick navigation:
00:04 *🤖 Setting up the intense.json file for the chatbot*
- Creating an intense.json file to categorize user inputs for the chatbot.
- Defining categories such as greetings, questions about prices, and goodbyes.
- Specifying patterns and static responses for each category to train the chatbot.
06:12 *💻 Coding the chatbot in Python*
- Importing necessary libraries including random, json, pickle, numpy, and nltk.
- Lemmatizing words to reduce them to their base form for better performance.
- Processing the intense.json file to prepare training data for the chatbot.
19:08 *🧠 Building the neural network model*
- Shuffling and converting training data into numpy arrays for features and labels.
- Creating a sequential model and adding layers including input, dense, and dropout layers.
- Using rectified linear unit (ReLU) activation function and stochastic gradient descent (SGD) optimizer for training.
20:46 *🧠 Building the Neural Network Model*
- Building a neural network model for the chatbot.
- Adding dense layers with specified neurons and activation functions.
- Defining optimizer parameters and compiling the model.
24:12 *💬 Setting up Chatbot Application*
- Setting up the chatbot application to use the trained model.
- Importing necessary libraries and loading the trained model.
- Defining functions for processing user input and generating responses.
27:05 *🧹 Cleaning and Preparing Input Data*
- Defining functions for cleaning up sentences and converting them into bags of words.
- Preprocessing input data to prepare it for prediction by the neural network.
- Ensuring that the input data format aligns with the model's requirements.
29:38 *🤖 Predicting Classes and Generating Responses*
- Implementing a function to predict classes based on input sentences using the model.
- Establishing a threshold for accepting predictions to manage uncertainty.
- Generating responses based on predicted classes and probabilities.
Made with HARPA AI
For anyone having issues with the model not running. change train_x and train_y into a tensor and adjust the input shape of the model to be 15, 5
what do you mean by change them into a tensor
can you share the code?
? - keras in "tensorflow.keras..." is not recognized by 'Pycharm', but it works anyway.
Changes:
- from tensorflow.keras.optimizers import SGD
+ from tensorflow.keras.optimizers.legacy import SGD
- training = np.array(training)
+training = np.array(training, dtype=object)
-sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
+sgd = SGD(learning_rate=0.01, decay=1e-6, momentum=0.9, nesterov=True)
Thank you. Great commentary and clear explanations. Easy to follow how you built up the application. Perfect.
Ah! Was waiting for this only!🔥
enjoy it! :)
Me too🤠
@@NeuralNine Hello, this error is returning: *lemmatize() missing 1 required positional argument: 'word'*
I would love to see a video about the theory, great video, thank you:)
Bro You are one of the most Underrated YT channel I've ever seen..... Keep up the good work : - )
brother please do not stop! you are awesome
The video got really good but we don’t really clarify what packages to download. I know you said what at the beginning at Imports but it still gives me error messages with Tensorflow.
For example: '
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. '
did you get it right??
Hey, did you find the solution?
PLEASE help
@@ibaadahmed5925 Hey, did you find the solution?
PLEASE help
ahhhhhh...BOSS!!! may your days be long
you've given me hope and reignited my passion
Hey bro, your programming style is sophistecated 🧑💻
So...as far as the machine learning goes, it's just a text classification algorithm. I would love to see a version of this with actual text generation as well!
I mean it would be possible to combine it with the text generation tutorial I made some time ago ^^
@@NeuralNine Can't seem to find it!
@@SimonTiger I was hoping to find a comment like yours here. This may be the video he is referring to. ruclips.net/video/QM5XDc4NQJo/видео.html
hey. where can i get source code? any idea?
@@NeuralNine YOU should really make that happen as a video!!!
20:42 very interested in the theory, I like how you explain and would be cool to hear it from you
when it comes to trading in the various financial markets the relevance of professional guidance should not be undervalued as it could be the key to any traders success in profit making
spot on! but the usual problem is discovering well grounded professionals who can be trusted. have you got any reconmendations?
i could not have said it any better.
@@piricontes2844 I will highly recommend Michael Branagh, he helped me secure a passive source of income, made life quiet easier for me as I no longer had to work round the clock. I'd check if he's taking new investors now, and also ask if I can share his contact information to the public.
@@JacobHKent i have stumbled upon a couple of articles by him, never occured to me to look him up. i would sincerely appreciated if you coild help with his contact info.
@@JacobHKent Mr Branagh is one of the most productive traders out there. i would not say hes the best at what he does but one thing is certain, hes a man of integrity and he certaainly gets results
I have to make one for school so this is perfect timing ;^)
Our school only do pascal bruh
it would be cool if you made a video where you combined a chatbot like this with/into a discord bot!
you'd just use discord.py to detect when a message is sent, use that message as the input for the AI, and output the AI's output as the discord message
@@owenknowles3796 didn't think about that thanks! Will try when computer switches on
@@pw5687 How'd it go?
Well done. As I am new to chatbot() and python. Your video helped to fill in all the gaps in Tim video. Thanks brother.
I love your videos! They're so useful :D I've just purchased your 7 in 1 book from amazon
sooo interested to the neural network theory!!! Love this channel so much, i've learned so much, thank you!!
Never seen this type of content before, really amazing
yeah, his tutorials are very applicable. i wonder what would happen to my knowledge if i carry one of that out each day for 1 month staright
Man do i love that intro 🔥
i have'nt watched your video before this video but now ican't stop watching your video
When will you open a Discord Server?
if you get an error with hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size =5, verbose=1 ), just delete "accuracy in model.compile
NIce video! Can you make an in-depth tutorial on making a friend-like chatbot that uses neural networks and NLP, and adapts it to modern libraries like Keras and TensorFlow? I've been making a project, but I've been having some issues.
Hey ...have u made the project?
Any progress?
Nice tutorial on basic Keras NN setup. The truth is there is no need for a NN here. What it does is a simple input text selector and a random generator to output the response text. You could do the same using regexp/similar text/soundex word matching.
I was hoping i wouldn't be the only one realizing this. Using a NN for this is such overkill.
This is an amazing tutorial brother, thanks for all the knowledge you've shared! You earned a subscriber!
Yes I’m very interested in neural network theory! 🙋♂️🙋♂️🙋♂️🙋♂️🙋♂️
Ah yes, now I can make a very own best friend who can understand me :DDDD
yeah, i am also making it for myself. 😀😉
same :D
@@blue_is_cool16 encouter any error ????
@@selwyntayong7286 yeah I needed to download the modules.
Which I did :D
Please put more videos like this bro, I needed some sorry more....
And if you are about to launch a video give a gif for that. That thrill will be enough for me to be happy. Don't get faded bro, we need you...
This was amazing! Thank you so much I have learned a lot :D
man I was just building a hard-coded chatbot, this vid came in the right time for me. thanks bro
@Hotdog_man2 Minecraft lol yea
for intent in intents['intents']:
for pattern in intent['patterns']:
word_list = nltk.word_tokenize(pattern)
words.append(word_list)
documents.append((word_list, intent['tag']))
if intent['tag'] not in classes:
classes.append(intent['tag'])
This showing me error
" For pattern in intent['patterns']
KeyError : 'patterns'
Please help me out!
bro your intro is fire
Can you make a series on neural network theory? This video was very helpful.Thanks
when i finished this chat i typed in terminal: " hello!"
the answer was "sad to see you go :( "
hahahahahahah i'm crying !!!!
thank you it's working perfectly
I have that exact error... how did you fix it?
@@fernandobarocio2796
He used the intention.py file to answer the users.
so you can use your own file or just google it you can find a lot of them.
it's not a big problem.
good luck.
this tutorial is very useful! can I have the project source code for self-learning?
training = np.array(training) throws an error!
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (12, 2) + inhomogeneous part.
Sorry if it's too late, but I solved this error with the following:
training_array = []
for item in training:
part1 = np.array(item[0])
part2 = np.array(item[-1])
list_items = [part1, part2]
training_array.append(list_items)
Then you can use 'training_array' np.array(training) like.
Hi NeuralNine, this is a great piece. I would like to ask you if this tutorial would work for another language. Would it be enough to just edit intents, to comply with the language I would like to use? And the second question, do you have some tutorial, on how to implement this bot to streamlabs chatbot for twitch?
I tried it with german words and all I had to do is define the language in the word_tokenize function:
nltk.word_tokenize(pattern,language='german')
hey. where can i get source code? any idea?
thank you ! needed this in my school project
#Dec 2023-
import random
import json
import numpy as np
import pickle
import tensorflow as tf
import nltk
from nltk.stem import WordNetLemmatizer
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation, Dropout
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.preprocessing.sequence import pad_sequences
# Download NLTK data
nltk.download('punkt')
nltk.download('wordnet')
lemmatizer = WordNetLemmatizer()
intents = json.loads(open('intents.json').read())
words = []
classes = []
documents = []
ignore_letters = ['?', ',', '!', '.']
for intent in intents['intents']:
for pattern in intent['patterns']:
word_list = nltk.word_tokenize(pattern)
documents.append((word_list, intent['tag']))
words.extend(word_list) # Append words to the 'words' list
if intent['tag'] not in classes:
classes.append(intent['tag'])
words = [lemmatizer.lemmatize(word.lower()) for word in words if word not in ignore_letters]
words = sorted(set(words))
classes = sorted(set(classes))
pickle.dump(words, open('words.pkl', 'wb'))
pickle.dump(classes, open('classes.pkl', 'wb'))
training = []
output_empty = [0] * len(classes)
for document in documents:
bag = []
word_patterns = document[0]
word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns]
# Create a bag of words with 1s and 0s
bag = [1 if word in word_patterns else 0 for word in words]
# Create the output row
output_row = list(output_empty)
output_row[classes.index(document[1])] = 1
# Append the bag and output_row as separate lists
training.append([bag, output_row])
# Shuffle the training data
random.shuffle(training)
# Split the training data into X and Y
train_x = np.array([item[0] for item in training])
train_y = np.array([item[1] for item in training])
model = Sequential()
model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(len(train_y[0]), activation='softmax'))
sgd = SGD(learning_rate=0.01, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
hist = model.fit(train_x, train_y, epochs=200, batch_size=5, verbose=1)
model.save('Chatbot_model.h5', hist)
print("Done!")
What in the world! Thankfully I found you and now I trained my model correctly. I was getting this error:
78 random.shuffle(training)
---> 79 training = np.array(training)
80
81 train_x = list(training[:, 0])
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (392, 2) + inhomogeneous part.
I don't know what to do with this I asked every gpts even got link of source code in github then also getting same error. I just copied your code and hit run and then thankfully it worked.
THANKS A LOT.
Your videos are always amazing, always i learn a lot from your videos 🤩🤩
appreciate it :D
@@NeuralNine Hey man for some reason whenever I say Hello or one of the greetings it says a goodbye response. Any idea why?
@@NeuralNine can i get the source code please
UNDERRATED , u deserve a million sub
Hey NeuralNine, really like the videos.
Could you please like zoom in to the code... Or like increase the font. Its kinda difficult to see the code especially when not on full screen.
Even when youre showing other stuff like how to install mingw for c++... The text looks really small
But i really love your content and learn a lot. So if you could address that i'd be stoked
on mobile just reverse pinch the video to zoom
Hey manx nice content, always excited when you post a new video
there is correction on line 51 in chatbot.py ."responses" should be replaced with "response"
I code exactly same but couldn't able to to write any msg after "GO! Bot is running". can you help me? how to sort it out
This helped me learn a lot about neural networks thanks!
btw if you struggle with translation to vscode on the importation of tensorflow instead type "from tensorflow.python.keras.layers ...." and so on
Thank you so much!! I was going crazy trying to find a solution.
Hi, great content! Although, is it possible for you to upload the code in your videos to a github repo? Thanks
That will be great!
the thing about this intelligent ai is just that its not context based cuz it don't have access in the conversation history
and this is how my creator came to life.
Thanks 👍 I was actually waiting for this.
This video is really great and this AI projects series is extraordinary
Awesome work bro!
I like your videos
Kudos to you
I suggest you make a tutorial video on show to deploy an AI CHATBOT to back-end server to improve responsiveness and present more details.
Are you ever going to make a tutorial on a chatbot that generates its own responses?
The code is not working.
output_row[classes.index(document[1])] = 1
IndexError: list index out of range
a series about NN/ ai in general would be dope
When I added training data to the intents.json file, I got this error, anybody who can help?
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 38 but received input with shape (None, 84)
I figured out that the 84 is just the amount of patterns in the intents.json file, but I haven't figured out why the input shape has to have a value of 38.
Traceback (most recent call last):
File "E:/CODEING/lapsever/test.py", line 20, in
model = load_model("chatbotmodel.h5")
File "C:\Users\Mr.Programmer\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "C:\Users\Mr.Programmer\PycharmProjects\pythonProject\venv\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 166, in load_model_from_hdf5
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'
error
Well, I followed along and as I ran it....this guy decided to reply "Hello" with "Talk to you later" LMAOO 😭Even a bot isnt interested in talking with me 😒
Love this but I think Levenshtain Distance fits better when doing small projects.
Can you please provide the files of the bot
(because mine didn't worked)
Just subscribbed to appriciate and realized I am the 100K subscriber XD
training = np.array(training) is returning an error, can you help?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[24], line 26
24 # shuffle our features and turn into np.array
25 random.shuffle(training)
---> 26 training = np.array(training)
28 # create train and test lists. X - patterns, Y - intents
29 train_x = list(training[:, 0])
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (27, 2) + inhomogeneous part.
Thanks for the Video Florian! 👏👏
my bot keeps saying the intent is goodbye even if I say "how are you?" it says hey or goodbye or talk to you later
I have similar problem.
my bot keeps saying "hi", ""hello", "what can i do for you", even if i ask "what is your name"
please help
If there’s nothing wrong with the preprocessing you probably have to find a way to properly tune the model with a test set and a training set to prevent under or overfitting.
Hey, I have a Problem after training , type error in last 2 functions, While true, get_response
If you guys keep getting goodbye messages for other things change the error_threshold to 0.5 and if that doesn't work change the epochs in training.py to 800
Can you please zoom a bit more on the code? Would be better to understand 🙂.
Works great! Im having this error when adding more than 3 intents though.
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 27 but received input with shape [None, 30]. :/
Me too! did you find the solution??
I found the error. I forgot to change the model name in the chatbot.py , it was .model but the correct is .h5
@@netofis omg thank you so much I've been searching for the solution to this error for an hour 😭
@@netofis Thank you so much, was struggling for 2 hours
I was recieving TypeError at 14:30
This solve for me
"
pip install self
nltk.download('wordnet')
import self
words = [lemmatizer.lemmatize(self, word) for word in words if word not in ignore_letters]
words = sorted(set(words))
"
22:08 Hi, i'm new to DL.. When we use Softmax, if there are (say)two outputs in the network, it will output probabilities like [.4 ,.6] or [.1, .9] or [.5, .5] etc right? (sum always 1).. so even if we enter some gibberish as input, there will always be some output(s) above error threshold of (say) .25.
How ill I tweak this so this won't happen? ( i mean if i enter "ahfliehf fsdlihfasdh" to bot, the outputs should be like something like [0.001, 0.00123])
Awesome tutorial, it worked right away! You definitely got me as a subscriber.
hey can u tell what extensions to download pls
Hello... i have tried to copy your code now in 2023 and apparently there is an issue with training = np.array(training) since the [bag, output_row] columns don't have the same dimensions (maybe I have copied something wrong along the way...).
I have came up with a solution that bypass the issue, although its quite a caveman style solution and I do not have the knowledge to understand its consequences, but it does not crash the code and allows me to train the chatbot.
solution:
when defining the dimensions of:
output_empty = [0] * len(classes)
instead do:
output_empty = [0] * len(words)
this way the dimensions of "bag" and "output_row" are the same. (It will fill the space with 0, so it shouldn't change the bot training accuracy... but what do I know :D )
Hey what about importing tensorflow, I tried copying too but mines showing error like 'rebuild tensorflow with appropriate compiler flags'
@@Kanishkaran.__ Not really sure, but as I figured lately its quite a lot about version compatibilities with TF and all these days. Try searching if your versions match.
@@bloodang6793 What's the version used here?
@@Kanishkaran.__ Hey, did you get a solution?
@@mysterious4496 no
Great video, I learned so much, thank you!
Hey, any idea how you'd get this to run with tflite?
Edit: Okay, I've gotten the model to run, but I realised nltk stemming is really slow. Is there a faster alternative?
(actually I'll try figure out exactly what's taking ages)
Edit #2: Nevermind, it all works, there's just a delay the first time the process is called for some reason (Which I'll try to trace and fix)
Thanks for the great tutorial, can't wait to setup my own personal assistant!
I think my comment on the previous video about automated comment reply initiated this topic
Hello, i am unable to install tensorflow!!please help
Use this video its very good and well we ruclips.net/video/zRY5lx-So-c/видео.html
tensorflow does not support python versions after 3.6.4, so you'll have to change your version
@@maxmayer3551 That's pure BS. It's available till Python 3.8
@@ratto751 I was using 3.8 and I had the same issue as this guy so I looked it up, read an article that told me tensorflow doesn't work beyond 3.6.4 so I switched versions and it completely fixed my issue. So if you really insist that my experience was purely circumstantial
@@maxmayer3551 Would you rather trust an article or the official TensorFlow GitHub and PyPi? I've been able to run TensorFlow on python 3.8. There must be some other problem with your PC since it works with 3.8 on mine.
You're so underrated bro
can i have the source code?
Give us the source code plsss
No
@@hereshaurya Yes?
No
@@hereshaurya Yes??
Bro was years ahead
As usual great video, excelent channel
thanks, that works(some code mistakes corrects by chatGPT) nice video
Btw Nesterov is to implement an accelerating learning rate ,I think
Can you post a video on how to extract entities from intents and deploy the chatbot on a website or something. thanks
This tutorial is fantastic! Thank you for sharing.
ruclips.net/channel/UC0Bn9e36XqiiNZp9ClkPUww
I'm trying to create a chatbot for customer care, it is going to be a live support agent for industries like Telecom companies, so after I finish with all the knowledge you have shared maybe I will have some questions and everything else.
Wow, it actually worked well. I made a bot using it
I learned a lot through this video. However since we have static replies for this exact project I believe that splitting the string from the user input into a list as you did, finding a key word and thus give the reply could be easily and faster done with if else statements. I get the educational manner for the AI part but because you didn’t exactly analyze the code that you used in the machine learning part because of the purpose of the video I will stick to my opinion having the thought of the purpose of the video being “build a chatbot” and not “use ai to create something”. Great video though❤
espero que puedas traducir este mensaje, pero solo quiero agradecerte porque me ayudaste mucho al basarme en este bot, saludos desde Mexico :)
Hello, just wanted to throw my feedback for you guys! Very good video (you should watch his neural network theory video, it helps a lot)
While implementing alongside you I would always get no more than 0.75 accuracy, BUT if for the first time we use lemmatize you put this:
words = [lemmatizer.lemmatize(word.lower()) for word in words if word not in symbols_to_ignore]
It increases the accurasy to 0.9 - 1. Which makes the AI much more efficient! Also in the cleaning up sentence fuction you might want to make the sentence lower cased :)
i am getting no error it just runs and then stops
It makes it much more efficient. Thanks for the comment :)
correct me if i'm wrong but his model overfitted right?
Wao that's made my day.... Thanks a lot for sharing such an insightful video
RUclips can I give this man million likes ?
men thank you for this totoriol, i download your video , creat ai chat bot ful system you show me many things i don't know her you are amazing thank you