Я пытаюсь узнать о библиотеке 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