Skip to content

Pranav016/Python-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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.
  • Chatterbot Corpus

  • 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 and chatterbot.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

    • The logic adapter returns a response based on known responses to the closest matches to the input statement.

    • chatterbot.logic.BestMatch

    • 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:

    1. Drop a on the Github Repository.

    2. Download Python IDE (recommended Anaconda IDE)
      Install Anaconda for Windows
      Install Anaconda for MacOS
      Install Anaconda for Linux

    3. Clone the Repo by going to your local Git Client and pushing this command:
      git clone https://github.com/Pranav016/Python-Chatbot.git

    4. 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.txt
      

      or

      Open the project in your Jupyter Notebook. Run these commands in it.

      
          !pip install chatterbot
          !pip install chatterbot_corpus
      

    Licensed under MIT LICENSE

About

Chatbot made using Chatterbot and Chatterbot Corpus packages.

Topics

Resources

License

Stars

Watchers

Forks