我正在尝试学习Python库Chatterbot。我使用文件向它提供了学习数据。但在很少的对话之后,它正在学习荒谬的事情,即使数据已经通过文件提供给它了。请告诉我怎么控制它。我的代码如下:
import chatterbot
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
import os
import sqlite3
bot = ChatBot('Joe',logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',
'threshold': 0.60,
'default_response': 'I am sorry, but I do not understand.'
}
])
bot.set_trainer(ListTrainer)
for files in os.listdir("C:/Users/tmr6kor/Desktop/conversations/"):
data = open('C:/Users/tmr6kor/Desktop/conversations/' + files,'r').readlines()
bot.train(data)
conn = sqlite3.connect('TestLogin.db')
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS log (userid text, name text)")
#conn.commit()
uid = str(input("Joe: May I know your userid?"))
uid.strip()
uid.lower()
if uid == 'no' or uid == ' never' or uid == 'no never':
print("Joe: Ok Goodbye! Stupid.")
exit(1)
c.execute("SELECT * FROM log WHERE userid = (?)",(uid,))
validTuple = c.fetchone()
newperson = 0
if validTuple == None:
print("Joe: Sorry you are not an authorised user. Koun ho bhai??? Do you want to Sign Up?")
f = 0
while f != 1:
choice = str(input("Type Yes or No"))
choice.lower()
if choice == 'yes' or choice == 'ya' or choice == 'yeah' or choice == 'y':
newperson = 1
temuid = str(input("Joe: Your user id please "))
temuname = str(input("Joe: Your Name "))
c.execute("SELECT * FROM log WHERE userid = (?)",(temuid,))
va = c.fetchone()
if va == None:
#c.execute("INSERT INTO log VALUES("+temuid+","+temuname+")")
c.execute("INSERT INTO log VALUES (?,?)",(temuid,temuname))
conn.commit()
f = 1
else:
print("This user id belongs to ",va[1],"and you are not ",va[1],"its a security issue so I cannot allow you to input your user id again. Good bye")
f = 1
exit(1)
elif choice == 'no' or choice == 'nopes' or choice == 'never' or choice == 'n':
print("Joe: Ok Thank you")
f = 1
exit(1)
else:
print("Joe: Sorry didn't get that. Stop writing faltu chizen.")
if newperson == 1:
userid = str(input("Joe: Please reenter your user id"))
else:
userid = uid
c.execute("SELECT * FROM log WHERE userid =(?)",(userid,))
validTuple = c.fetchone()
username = validTuple[1]
print("Joe: Hello ",username)
while True:
request = str(input(username+": "))
if request.strip() != 'bye' and request != 'Bye':
response = bot.get_response(request)
print("Joe: ",response)
else:
print("Joe: Ya taddah")
break
conn.close()我的训练数据如下:
文件1
Hi!\n
Hey i am Joe
hi
hello i am Joe
hello
heya
How are you?
I am fine. Thank you. How are you?
I am fine too.
Thats great.
Tell me something about yourself
I am Joe.I work for Bosch.
I work for Bosch too.
okay thats great.
Bye
see you
bye
see you
thanks
you are welcome文件2
Hey! I need a chicken bucket
what kind of chicken bucket?? chicken pop corn, chicken smoky grilled, chicken wings????
I need a chicken pop corn bucket
large or small??
large chicken pop corn
okay it costs Rs 149. Your order is on its way.
small
small what??? Please specify.
small chicken popcorn bucket
okay it costs Rs 95. Your order is on its way. Please have a seat.
Chicken Smoky grilled
Large or small???
Large chicken bucket
Large Chicken bucket of Smoky grilled chicken costs Rs 199
And what about small chicken somky grilled???
It costs Rs 119
What about Chicken wings??
Sorry out of Order我的输出:
Joe: Hello Sarthak Mahapatra
Sarthak Mahapatra: I need a chicken bucket
Joe: I need a chicken bucket发布于 2018-05-03 17:35:10
尝试删除你的sqlite数据库文件“TestLogin.db”,然后再次执行Train你的机器人,然后添加它...如果你需要任何帮助,请告诉我。
https://stackoverflow.com/questions/49023427
复制相似问题