Python chatterbot正在学习除学习数据之外的任何东西

时间:2018-02-28 06:42:09

标签: python python-3.x chatterbot

我正在尝试学习名为Chatterbot的Python库。我使用文件向它提供了学习数据。但是在几次谈话之后,即使数据已经使用文件提供给它,它也在学习荒谬的东西。请告诉我如何控制它。我的代码如下 -

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

1 个答案:

答案 0 :(得分:0)

尝试删除sqlite数据库文件“TestLogin.db” 在执行之前再次训练你的机器人然后添加它... 如果您需要任何帮助,请告诉我。