https://github.com/pranav016/python-chatbot
Chatbot made using Chatterbot and Chatterbot Corpus packages.
https://github.com/pranav016/python-chatbot
chatterbot python-chatbot
Last synced: 3 months ago
JSON representation
Chatbot made using Chatterbot and Chatterbot Corpus packages.
- Host: GitHub
- URL: https://github.com/pranav016/python-chatbot
- Owner: Pranav016
- License: mit
- Created: 2020-11-01T17:17:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T23:28:53.000Z (over 4 years ago)
- Last Synced: 2025-03-22T03:51:17.263Z (3 months ago)
- Topics: chatterbot, python-chatbot
- Language: Jupyter Notebook
- Homepage:
- Size: 202 KB
- Stars: 6
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Python Chatbot
What is a Chatbot?
A chatbot is a computer program that's designed to simulate human conversation. Users communicate with these tools using a chat interface or via voice, just like they would converse with another person. Chatbots interpret the words given to them by a person and provide a pre-set answer.
Artificial intelligence, which brings into play machine learning and Natural language Processing (NLP) for building bot or chatbot, is specifically designed to unravel the smooth interaction between humans and computers.
How can Chatbots be useful?
- Increases operational efficiency.
- Automating customer request fulfillment.
- Handling basic queries, which in turn free employees to work for complex & higher value inquiries.
- Offers Multi-language support.
- Saves time & effort by automating customer support.
- Improves the response rate as well as customer engagement.
- Personalization of communication
Packages used:
Chatterbot
Chatterbot Corpus
ChatterBot is a Python library that makes it easy to generate automated responses to a user’s input. ChatterBot uses a selection of machine learning algorithms to produce different types of responses.
This is a corpus of dialog data that is included in the chatterbot module.
How does this chatbot work?

After importing chatterbot and chatterbot corpus we create an instance of our chatbot class. We use logical adapters such as
chatterbot.logic.BestMatch
andchatterbot.logic.TimeLogicAdapter
.
bot = ChatBot(
'Pranav',
logic_adapters=[
'chatterbot.logic.BestMatch',
'chatterbot.logic.TimeLogicAdapter'],
)
Logical Adapters
Logic adapters determine the logic for how ChatterBot selects a response to a given input statement. It is possible to enter any number of logic adapters for your bot to use. If multiple adapters are used, then the bot will return the response with the highest calculated confidence value. If multiple adapters return the same confidence, then the adapter that is entered into the list first will take priority.
chatterbot.logic.BestMatch
chatterbot.logic.BestMatch
The logic adapter returns a response based on known responses to the closest matches to the input statement.
The TimeLogicAdapter identifies statements in which a question about the current time is asked. If a matching question is detected, then a response containing the current time is returned.
Training our chatbot
ChatterBot includes tools that help simplify the process of training a chat bot instance. ChatterBot’s training process involves loading example dialog into the chat bot’s database. This either creates or builds upon the graph data structure that represents the sets of known statements and responses. When a chat bot trainer is provided with a data set, it creates the necessary entries in the chat bot’s knowledge graph so that the statement inputs and responses are correctly represented.
from chatterbot.trainers import ChatterBotCorpusTrainer
We can also train our chatterbot on a list using chatterbot.trainers.ListTrainer
Making an instance of the ChatterbotCorpusTrainer
trainer.train('chatterbot.corpus.english')
Here I have trained the chatbot using the inbuilt data in the chatterbot corpus.
trainer.train('chatterbot.corpus.english')

For more info on the data, refer to the official repo of the ChatterbotCorpus package.
This piece of code is pretty straight forward. It uses a while loop to get responses untill we get a 'Bye' from the user.
name=input("Enter Your Name: ")
print("Hi "+name+", how can I help you?")
while True:
request=input(name+':')
if request=='Bye' or request =='bye':
print('Pranav: Bye')
break
else:
response=bot.get_response(request)
print('Pranav:',response)
Here get_response()
is a method of chatbot instance. It return the bot’s response based on the input.
Environment Setup and Local Installation:
- Drop a ★ on the Github Repository.
- Download Python IDE (recommended Anaconda IDE)
Install Anaconda for Windows
Install Anaconda for MacOS
Install Anaconda for Linux
- Clone the Repo by going to your local Git Client and pushing this command:
git clone https://github.com/Pranav016/Python-Chatbot.git
- Go to the AnacondaPrompt and use this command to install the packages. Open Jupyter Notebook to work-on/ use the chatbot:
pip install -r requirements.txtor
Open the project in your Jupyter Notebook.
Run these commands in it.
!pip install chatterbot
!pip install chatterbot_corpus