Intelligent AI Chatbot in Python

preview_player
Показать описание
In today's video, we are going to build an intelligent AI chatbot using neural networks and natural language processing in Python.

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚

🌐 Social Media & Contact 🌐

Timestamps
(0:00) Intro
(0:18) General Structure
(2:16) Setting Up Intents
(6:48) Load Training Data
(13:35) Prepare Training Data
(19:40) Build Neural Network
(24:10) Train Neural Network
(24:35) Build Chatbot
(33:34) Demonstration
(35:08) Outro
Рекомендации по теме
Комментарии
Автор

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 =

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:


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 = for word in wordPatterns]
for word in words:
bag.append(1) if word in wordPatterns else bag.append(0)

outputRow = list(outputEmpty)
= 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.Dense(64, activation = 'relu'))

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)

print('Done')

JosephElliott-kxyj
Автор

Man, you are THE ONLY ONE explaining this intent type of neural net-based chatbot. Thanks a lot

joeljohn
Автор

Awesome content! when are we getting the biceps tutorial tho?

tomas
Автор

I love your videos! They're so useful :D I've just purchased your 7 in 1 book from amazon

foggers
Автор

Videos on neural network theory would be fantastic! Thanks again for another great video!

alex_mahone
Автор

sooo interested to the neural network theory!!! Love this channel so much, i've learned so much, thank you!!

lorenzoricciardi
Автор

Thank you. Great commentary and clear explanations. Easy to follow how you built up the application. Perfect.

BarryGoodall
Автор

I would love to see a video about the theory, great video, thank you:)

kifercastillo
Автор

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

ChannelName
Автор

This is an amazing tutorial brother, thanks for all the knowledge you've shared! You earned a subscriber!

abdulalimbaig
Автор

This was amazing! Thank you so much I have learned a lot :D

TISIMTISMTISM
Автор

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.

cubs
Автор

Thanks 👍 I was actually waiting for this.

ok-
Автор

Hey bro, your programming style is sophistecated 🧑‍💻

cardosofede
Автор

Never seen this type of content before, really amazing

scholar
Автор

Well done. As I am new to chatbot() and python. Your video helped to fill in all the gaps in Tim video. Thanks brother.

tansimbee
Автор

brother please do not stop! you are awesome

cartf
Автор

Can you make a series on neural network theory? This video was very helpful.Thanks

odiushealer
Автор

I have to make one for school so this is perfect timing ;^)

juliusmakowski
Автор

Great video, I learned so much, thank you!

CritiKylie