1、聊天机器人行业背景
聊天机器人主要用于电商行业
新闻行业
财经行业
2、聊天机器人起源和发展
第一台机器人IBM-701,基于计算机语言basic产生的
聊天机器人发展中的问题:
- 那么聊天机器人是否智能
- 学习能力如何
- 自生级能力如何
3、聊天机器人的分类
- 按照领域分类
固定领域例如天气查询、疾病诊治
开放领域应用例如微软小冰
- 按照模式来分
encoder对于输入进行编码成vector,然后decoder进行解码,生成回答。
- 按照功能来分
4、如何构建最简单的聊天机器人
例如:
5、基于规则实现的简单聊天机器人(代码实现)
import random
#打招呼
greetings=['hola','hello','hi','Hi','hey','Hey']
#回复
random_greetings=random.choice(greetings)
question=["How are you?",'How Are you doing?']
responses=['Okay','I’m fine']
random_response=random.choice(responses)
while True:
userInput=input(">>>")
if userInput in greetings:
print(random_greetings)
elif userInput in question:
print(random_response)
elif userInput =='bye':
break
else:
print('I did not konw what you said')
运行结果:
上面的实现过于简单,下面使用关键词进行判断输入的话是什么意思,然后进行回答
import random
from nltk import word_tokenize
# 打招呼
greetings = ['hola', 'hello', 'hi', 'Hi', 'hey', 'Hey']
# 回复
random_greetings = random.choice(greetings)
question = ["break", 'holiday', 'vocation', 'weekend']
responses = ['It was nice', 'I went to Paris', 'Sadly, I just stayed at home ']
random_response = random.choice(responses)
while True:
userInput = input(">>>")
# 清理输入
cleaned_input = word_tokenize(userInput)
# 对比关键词
if not set(cleaned_input).isdisjoint(greetings):
print(random_greetings)
elif not set(cleaned_input).isdisjoint(question):
print(random_response)
elif userInput == 'bye':
break
else:
print('I did not know what you said')
运行结果: