Convert Figma logo to code with AI

gunthercox logoChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots

14,020
4,431
14,020
408

Top Related Projects

Large-scale pretraining for dialogue

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.

An open source library for deep learning end-to-end dialog systems and chatbots.

12,494

The open-source hub to build & deploy GPT/LLM Agents ⚡️

Bot Framework provides the most comprehensive experience for building conversation applications.

Quick Overview

ChatterBot is an open-source Python library for creating chatbots. It uses machine learning algorithms to generate responses based on collections of known conversations, making it easy to create chatbots that can engage in natural language conversations.

Pros

  • Easy to set up and use, with a simple API
  • Supports multiple languages and can be trained on custom data
  • Highly customizable with various storage adapters and logic adapters
  • Active community and regular updates

Cons

  • May require significant training data for optimal performance
  • Response generation can be slow for complex conversations
  • Limited out-of-the-box natural language understanding capabilities
  • Potential for generating inappropriate responses if not properly trained

Code Examples

  1. Creating a basic chatbot:
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot('MyBot')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')

response = chatbot.get_response('Hello, how are you?')
print(response)
  1. Training the chatbot with custom data:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer

chatbot = ChatBot('CustomBot')
trainer = ListTrainer(chatbot)

trainer.train([
    "Hi",
    "Hello",
    "How are you?",
    "I'm doing well, thank you!",
    "That's great to hear.",
    "Thank you.",
    "You're welcome."
])
  1. Using a different storage adapter:
from chatterbot import ChatBot
import chatterbot_sqlalchemy

chatbot = ChatBot(
    'SQLBot',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    database_uri='sqlite:///database.sqlite3'
)

Getting Started

To get started with ChatterBot, follow these steps:

  1. Install ChatterBot:
pip install chatterbot
  1. Create a new Python file and import the necessary modules:
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
  1. Create and train a chatbot:
chatbot = ChatBot('MyBot')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')
  1. Start a conversation:
while True:
    user_input = input("You: ")
    if user_input.lower() == 'quit':
        break
    response = chatbot.get_response(user_input)
    print(f"Bot: {response}")

This will create a simple command-line chatbot that you can interact with. You can further customize and expand its capabilities as needed.

Competitor Comparisons

Large-scale pretraining for dialogue

Pros of DialoGPT

  • More advanced language understanding and generation capabilities
  • Pre-trained on a large dataset, allowing for more natural conversations
  • Better handling of context and multi-turn dialogues

Cons of DialoGPT

  • Requires more computational resources and GPU for optimal performance
  • Less customizable compared to ChatterBot's rule-based approach
  • Potential for generating inappropriate or biased responses

Code Comparison

ChatterBot:

from chatterbot import ChatBot

chatbot = ChatBot("MyBot")
response = chatbot.get_response("Hello, how are you?")
print(response)

DialoGPT:

from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")

input_ids = tokenizer.encode("Hello, how are you?", return_tensors="pt")
response = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(response[0], skip_special_tokens=True))

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.

Pros of transformers

  • Offers a wide range of state-of-the-art pre-trained models for various NLP tasks
  • Supports multiple deep learning frameworks (PyTorch, TensorFlow)
  • Actively maintained with frequent updates and a large community

Cons of transformers

  • Steeper learning curve due to its complexity and extensive features
  • Requires more computational resources for training and inference
  • May be overkill for simpler chatbot applications

Code comparison

ChatterBot:

from chatterbot import ChatBot

chatbot = ChatBot("My Chatbot")
response = chatbot.get_response("Hello, how are you?")
print(response)

transformers:

from transformers import pipeline

chatbot = pipeline("conversational")
response = chatbot("Hello, how are you?")
print(response[0]["generated_text"])

Summary

ChatterBot is a simpler, more lightweight option for building basic chatbots, while transformers offers more advanced NLP capabilities and pre-trained models. ChatterBot is easier to set up and use for beginners, but transformers provides more flexibility and power for complex language tasks. The choice between the two depends on the specific requirements of your project and your level of expertise in NLP and deep learning.

An open source library for deep learning end-to-end dialog systems and chatbots.

Pros of DeepPavlov

  • More advanced NLP capabilities, including named entity recognition and question answering
  • Supports multiple languages out of the box
  • Offers pre-trained models for various NLP tasks

Cons of DeepPavlov

  • Steeper learning curve due to its complexity
  • Requires more computational resources
  • Less suitable for simple chatbot applications

Code Comparison

ChatterBot:

from chatterbot import ChatBot

chatbot = ChatBot("My Bot")
response = chatbot.get_response("Hello, how are you?")
print(response)

DeepPavlov:

from deeppavlov import build_model, configs

model = build_model(configs.squad.squad_bert, download=True)
result = model(["Text context here"], ["Question here"])
print(result)

DeepPavlov offers more advanced NLP capabilities but requires more setup and configuration. ChatterBot is simpler to use for basic chatbot functionality, while DeepPavlov is better suited for complex NLP tasks and multi-language support. ChatterBot is more lightweight and easier to integrate into simple projects, whereas DeepPavlov provides pre-trained models and advanced features for sophisticated NLP applications.

12,494

The open-source hub to build & deploy GPT/LLM Agents ⚡️

Pros of Botpress

  • More comprehensive platform with visual flow builder and built-in NLU
  • Supports multiple channels (web, Messenger, Slack, etc.) out of the box
  • Active development and regular updates

Cons of Botpress

  • Steeper learning curve due to more complex architecture
  • Requires more system resources to run
  • Less straightforward for simple chatbot implementations

Code Comparison

ChatterBot example:

from chatterbot import ChatBot

chatbot = ChatBot("My ChatBot")
response = chatbot.get_response("Hello, how are you?")
print(response)

Botpress example:

const botpress = require('botpress')

const bot = new botpress({
  botfile: '<path to botfile.js>'
})

bot.hear(/hello/i, (event, next) => {
  event.reply('Hello, human!')
})

Both libraries offer simple ways to create chatbots, but Botpress provides a more extensive framework for building complex conversational interfaces. ChatterBot is Python-based and focuses on machine learning for responses, while Botpress uses JavaScript and offers a modular architecture with pre-built components for various functionalities.

Bot Framework provides the most comprehensive experience for building conversation applications.

Pros of botframework-sdk

  • More comprehensive and enterprise-ready solution for building conversational AI
  • Supports multiple channels and platforms (web, mobile, Slack, Teams, etc.)
  • Offers advanced features like language understanding and dialog management

Cons of botframework-sdk

  • Steeper learning curve and more complex setup compared to ChatterBot
  • Requires more resources and infrastructure to run effectively
  • May be overkill for simple chatbot projects or small-scale applications

Code Comparison

ChatterBot example:

from chatterbot import ChatBot

chatbot = ChatBot("My Bot")
response = chatbot.get_response("Hello, how are you?")
print(response)

botframework-sdk example:

from botbuilder.core import TurnContext, ActivityHandler
from botbuilder.schema import Activity

class MyBot(ActivityHandler):
    async def on_message_activity(self, turn_context: TurnContext):
        await turn_context.send_activity(f"You said: {turn_context.activity.text}")

ChatterBot is simpler and more straightforward for basic chatbot functionality, while botframework-sdk offers more flexibility and advanced features for complex conversational AI applications. ChatterBot is better suited for quick prototypes or simple chat interactions, whereas botframework-sdk is designed for scalable, multi-channel bot development in enterprise environments.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ChatterBot: Machine learning in Python

ChatterBot

ChatterBot is a machine-learning based conversational dialog engine build in Python which makes it possible to generate responses based on collections of known conversations. The language independent design of ChatterBot allows it to be trained to speak any language.

Package Version Python 3.6 Django 2.0 Requirements Status Build Status Documentation Status Coverage Status Code Climate Join the chat at https://gitter.im/chatterbot/Lobby

An example of typical input would be something like this:

user: Good morning! How are you doing?
bot: I am doing very well, thank you for asking.
user: You're welcome.
bot: Do you like hats?

How it works

An untrained instance of ChatterBot starts off with no knowledge of how to communicate. Each time a user enters a statement, the library saves the text that they entered and the text that the statement was in response to. As ChatterBot receives more input the number of responses that it can reply and the accuracy of each response in relation to the input statement increase. The program selects the closest matching response by searching for the closest matching known statement that matches the input, it then returns the most likely response to that statement based on how frequently each response is issued by the people the bot communicates with.

Installation

This package can be installed from PyPi by running:

pip install chatterbot

Basic Usage

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot('Ron Obvious')

# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)

# Train the chatbot based on the english corpus
trainer.train("chatterbot.corpus.english")

# Get a response to an input statement
chatbot.get_response("Hello, how are you today?")

Training data

ChatterBot comes with a data utility module that can be used to train chat bots. At the moment there is training data for over a dozen languages in this module. Contributions of additional training data or training data in other languages would be greatly appreciated. Take a look at the data files in the chatterbot-corpus package if you are interested in contributing.

from chatterbot.trainers import ChatterBotCorpusTrainer

# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)

# Train based on the english corpus
trainer.train("chatterbot.corpus.english")

# Train based on english greetings corpus
trainer.train("chatterbot.corpus.english.greetings")

# Train based on the english conversations corpus
trainer.train("chatterbot.corpus.english.conversations")

Corpus contributions are welcome! Please make a pull request.

Documentation

View the documentation for ChatterBot on Read the Docs.

To build the documentation yourself using Sphinx, run:

sphinx-build -b html docs/ build/

Examples

For examples, see the examples directory in this project's git repository.

There is also an example Django project using ChatterBot, as well as an example Flask project using ChatterBot.

History

See release notes for changes https://github.com/gunthercox/ChatterBot/releases

Development pattern for contributors

  1. Create a fork of the main ChatterBot repository on GitHub.
  2. Make your changes in a branch named something different from master, e.g. create a new branch my-pull-request.
  3. Create a pull request.
  4. Please follow the Python style guide for PEP-8.
  5. Use the projects built-in automated testing. to help make sure that your contribution is free from errors.

License

ChatterBot is licensed under the BSD 3-clause license.