5分钟内搭建你的第一个Python聊天机器人

前言

在人工智能时代,聊天机器人日益流行。它是业界设计用来简化人机交互的最新工具。从电子商务到医疗保健机构,每个人都希望使用Chatbot与用户进行交互。

什么是聊天机器人

聊天机器人是一种软件应用程序,用于通过文本或文本到语音进行在线聊天对话,而不是与真人代理直接接触。-根据维基百科。

聊天机器人的类型

聊天机器人可以分为两类

  • 基于规则的
  • 自学习

基于规则的: -基于规则的聊天机器人训练聊天机器人回答基于预先训练的规则的问题。这些类型的聊天机器人很适合进行简单的查询。

自主学习聊天机器人: 自主学习聊天机器人基于机器学习算法,它们比基于规则的聊天机器人更聪明。他们可以自己学习。

聊天机器人是如何工作的

由人工智能驱动的聊天机器人是智能的,也可以自己学习。它们使用自然语言处理和机器学习算法来学习和获取数据。

例如:谷歌助手,Alexa, Siri

智能的人工智能聊天机器人提供用户数据,并学习和尝试提高自己。他们用复杂的人工智能算法分析它,并以文本或语音的形式输出响应。

由于这些机器人可以从行为和经验中学习,它们可以对广泛的查询和命令作出回应。

开始搭建

今天,我们将使用ChatterBot库创建python chatbot。让我们开始吧!

1. 创建虚拟环境

pipenv是一个轻松创建虚拟环境的python库。

pip install 
pipenv pipenv install 
加python学习qq群:775690737 送python零基础入门学习资料+99个源码

2. 安装库

我们将使用ChatterBot库来创建简单的Python Chatbot。通过pip命令安装chatterbot和chatterbot_corpus。

pipenv install chatterbot 
pipenv install chatterbot_corpus  
加python学习qq群:775690737 送python零基础入门学习资料+99个源码

3.创造和训练聊天机器人

from chatterbot import ChatBot 
from chatterbot.trainers import ChatterBotCorpusTrainer 
BOTNAME = "Pyter" 
def start():     
bot = ChatBot(BOTNAME,
         logic_adapters=[ 
        {
             'import_path': 'chatterbot.logic.BestMatch',
             'default_response': 'I am sorry, but I do not understand.',
             'maximum_similarity_threshold': 0.90,
         },
      ], 
      preprocessors = [
             "chatterbot.preprocessors.clean_whitespace",
         ],
         input_adaptor="chatterbot.input.TerminalAdaptor",
         output_adaptor="chatterbot.output.TerminalAdaptor",
         database_uri='sqlite:///database.sqlite3')
     trainer = ChatterBotCorpusTrainer(bot)
     # Train based on the english corpus
     trainer.train(
         "chatterbot.corpus.english",
         "chatterbot.corpus.english.greetings",
         "chatterbot.corpus.english.conversations",
      )
     print(f"Hello I am {BOTNAME}")
     while True:
         try:
             bot_input = input("You: ")
             bot_respose = bot.get_response(bot_input)
             print(f"{BOTNAME}: {bot_respose}")
         except(KeyboardInterrupt, EOFError, SystemExit):
             break
 if __name__ == "__main__":
     start()  
加python学习qq群:775690737 送python零基础入门学习资料+99个源码

 

by Sumit Raj Apress 2019-02-04 192 pages Build your own chatbot using Python and open source tools. This book begins with an introduction to chatbots where you will gain vital information on their architecture. You will then dive straight into natural language processing with the natural language toolkit (NLTK) for building a custom language processing platform for your chatbot. With this foundation, you will take a look at different natural language processing techniques so that you can choose the right one for you. The next stage is to learn to build a chatbot using the API.ai platform and define its intents and entities. During this example, you will learn to enable communication with your bot and also take a look at key points of its integration and deployment. The final chapter of Building Chatbots with Python teaches you how to build, train, and deploy your very own chatbot. Using open source libraries and machine learning techniques you will learn to predict conditions for your bot and develop a conversational agent as a web application. Finally you will deploy your chatbot on your own server with AWS. What You Will Learn Gain the basics of natural language processing using Python Collect data and train your data for the chatbot Build your chatbot from scratch as a web app Integrate your chatbots with Facebook, Slack, and Telegram Deploy chatbots on your own server Who This Book Is For Intermediate Python developers who have no idea about chatbots. Developers with basic Python programming knowledge can also take advantage of the book.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值