gunthercox / ChatterBot

ChatterBot is a machine learning, conversational dialog engine for creating chat bots
https://chatterbot.readthedocs.io
BSD 3-Clause "New" or "Revised" License
13.99k stars 4.43k forks source link

Allow replies to be changed after then have been learned #696

Closed lucasjinreal closed 5 years ago

lucasjinreal commented 7 years ago

Hi, this project are very elgant and clean. I like this style. I have 2 issue consider about the design about this framework:

Wish get discuss about there puzzels, if they are already solve, could u please teach me how to implement in chatterbot?many thanks pal.

shousunny commented 7 years ago

i met the same problem as you .once a problem 's answer is set , it 's can't be changed .

vkosuri commented 7 years ago

@jinfagang Thanks for your inputs, May be i don't have exact answers to your questions, but there are some workarounds to do so.

I found that, once a statement store into database like mongo, I can not replace it, that means, if previous reply is wrong by bot, I can not fix that, maybe there are some flag allow me to override that?

There is learning_feedback_example which will provide a workaround/trick to do.

Another things is about the reply, the bot learned one question and an according answer, So if I asked that question twice, the answer would be same forever and never change, this is not good, even not intelligent than I using an random.choice to choose random condidate replies.

I think for every question the occurrence count will increase, I think this area needs to improve, @gunthercox Master do you any comments on this question. However you could write your own logic adapter to fulfill your needs

Wish get discuss about there puzzels

I don't have any idea about puzzles, could you please elaborate more on this question?

lucasjinreal commented 7 years ago

My English already bad. Puzzles sounds like mystery but I want to express meaning is just questions.

bobstheman commented 5 years ago

I was hoping someone posted an update to this question. How do you fix a bad comment/reply that the chatbot makes? If it says something stupid, can you edit the reply with a more intelligent one?

gunthercox commented 5 years ago

@bobstheman This isn't something that is build into ChatterBot, but it is possible to use custom programming to edit a reply in whatever database you are using. This can also be done manually using a command line database client or a GUI client of your choosing.

bobstheman commented 5 years ago

Please show how. I currently finished the "basics" of python using the python crash course book, so I'm a new programmer. However, I am fascinated by your chatterbot. It's an amazing bot other than when it says something goofy. If I were able to manually remove the goofy replies I think I'd have pretty much a "perfect bot". Please, do give examples how to manually edit the bot using windows 10 command line or windows 10 gui. Thanks in advance for your time.

gunthercox commented 5 years ago

I'd be happy to post some examples. I'll create them as soon as I can.

gunthercox commented 5 years ago

I usually use Sqlectron for changes like this (https://sqlectron.github.io/). There are many other database clients out there if there is a different one that you prefer to use.

After downloading and installing Sqlectron, I connect it to the Sqlite database that my chat bot uses.

To add a database, click the "Add" button and fill out the form with the information that Sqlectron needs to connect to your database.

screenshot from 2018-12-03 17-29-27

For "Initial Database/Keyspace" I entered /home/gcox/GitHub/ChatterBot/db.sqlite3, your database will likely be in a different location on your computer.

Press the "Test" button to make sure that Sqlectron can connect to the database. If it can, then click "Save".

After you've tested and saved the connection, click "Connect" on then main screen.

screenshot from 2018-12-03 17-38-45

After you connect to the database you will be able to view the tables that it contains and the columns in each table.

screenshot from 2018-12-04 02-05-19

Then you can enter a SQL query to interact with the database.

For example:

SELECT * FROM "statement" LIMIT 100

screenshot from 2018-12-03 17-40-26

This SQL query will show all fields for the "statement" table for the first 100 statements that the database contains.

To modify a statement, you can do the following

UPDATE "statement" SET "text"="New Text" WHERE "text"="Old Text";

After pressing the "Execute" button, your change will be made.

screenshot from 2018-12-04 02-04-02

Similar to updating, a statement can be deleted as shown below

DELETE FROM "statement" WHERE "text"="Old Text";

screenshot from 2018-12-04 02-10-09


I hope this helps. Please let me know if you have any questions.

bobstheman commented 5 years ago

Thanks for the reply and the information. I'm going to give this a go tomorrow. :)

bobstheman commented 5 years ago

I'm not doing something right with the ---------> UPDATE "statement" SET "text"="New Text" WHERE "text"="Old Text";

I'm connected to the database and can see the data but getting an error when I try to edit it. SQLITE_ERROR: near "UPDATE": syntax error errno: 1 code: SQLITE_ERROR name: Error

Can you please show a screen shot of an actual update/edit? Also, can you show how to delete a comment if you didn't want to change it but just delete it? Thanks gunthercox.

gunthercox commented 5 years ago

Sure, I've updated my previous comment to include some additional screenshots.

bobstheman commented 5 years ago

Thanks again. Is it sql that I need to learn now? I'm a newb, please forgive my ignorance, still getting the hang of programming. The python crashcourse book helped a lot but I need to learn more. I'm fascinated with machine learning/ai and would really like to get deeper into the subject. I recently bought the mathtutordvd.com full course to learn physics, algebra, calculus etc. to program tensorflow but to be honest I'm lost. Really could use some advice how to proceed. In the math course I'm only in algebra 1 right now and the math needed for tensorflow is scary. Tensorflow looks like chinese to me at the moment. How would your proceed if you were me with only algebra 1 and being a newb to the basics of python? Really crazy about ai, but wondering if I'm biting off more than I can chew :)

I sure appreciate your time and help.

bobstheman commented 5 years ago

Ok, tried it again, I put UPDATE "4" SET "text"="Are you alive?" WHERE "text"="Are you conscious";

I'm still doing something wrong. I tried to edit line 4 but it says no such table. Not sure how I pick a specific line to edit. I was able to use the delete example correctly that you showed though. Have patience please, I know my newbness is showing.

gunthercox commented 5 years ago

SQL is fairly easy to learn, I'd say that there are only a handful of key concepts that are important to learn (create, retrieve, update, and delete). You've already seen an example of three of those in the screenshots I posted so I'll leave it to you to look up the fourth :slightly_smiling_face:

I'd suggest learning about AI and machine learning in the following order. This is definitely not an exhaustive list, but generally it plots out a few useful points on the road map.

  1. Non-AI programming: Binary search, depth first search, breadth first search, etc.
  2. Bayesian Networks https://en.wikipedia.org/wiki/Bayesian_network
  3. Neural Networks
  4. Deep learning

If your interested in language processing then I'd recommend checking out the NLTK Book. It's very good and it has a lot of very useful and practical examples https://www.nltk.org/book/


You can pick a specific line to edit by changing the WHERE clause. The syntax is UPDATE <table name> SET <value to set> WHERE <values to match> so change your query to UPDATE "statement" SET "text"="New Text" WHERE "id"=4; to edit row 4.

bobstheman commented 5 years ago

Thanks for the follow up. I'll be looking into that info you just shared for sure.

Snooping around in sqlectron, I noticed you can right click on the panel on the left side of the screen and it will do things. I left clicked on statement and I'm able to pull up all kinds of data in the main window. Do all of those entries have to be changed? Or will editing a single response change the entire database? Is there any way you'd be willing to make a short youtube video for the github group or post one on your main website page? Sorry, I know it's asking a lot but I'm sure there are others that would benefit from a short video. I'm sure if you had a youtube channel for your bot, people would go crazy over it.

Lastly, do you have one of your bots online for others to interact with? It would be great to get one of your bots online. I'm in for pitching in on a website etc. via paypal if needed.

gunthercox commented 5 years ago

Do all of those entries have to be changed? Or will editing a single response change the entire database?

If you update them by ID, it will only change that one row. However, there are ways to update multiple rows at the same time. To provide an example:

This query updates the row with the id of 4 so that it's text says "New Text".

UPDATE "statement" SET "text"="New Text" WHERE "id"=4;

This query updates every row that has the text "Old Text" so that it says "New Text".

UPDATE "statement" SET "text"="New Text" WHERE "text="Old Text";

Is there any way you'd be willing to make a short youtube video for the github group or post one on your main website page?

I'm sure there are plenty of SQL tutorial videos out there already. These ones look pretty good: https://www.khanacademy.org/computing/computer-programming/sql

Lastly, do you have one of your bots online for others to interact with?

I don't currently. At some point I'll put one up in the Gitter chat. There is a good example created by @vkosuri that is currently running on Heroku.

bobstheman commented 5 years ago

Awesome. Let me know if you need contributions to get the chatbot up and running online. I'll be the first to donate via paypal. Kudos!

bobstheman commented 5 years ago

Hey Gunther,

I've been editing the bots sql database file with the sqlectron. I've been able to delete and change statements now but for some reason when I go to change the response "reply", it changes the question instead of the reply. What I mean is, the changes are happening in the "text" field instead of the "statement_text" field. I don't want change the question, I want to change the reply. I'm editing the "statement" and also the "response" but only the "text" field is changing. I hope I'm explaining this clearly.

Just need help with editing the "reply" to a question. Which it's not letting me do.

chatbot edit sql

gunthercox commented 5 years ago

You'll need to make sure that if you edit the response table that you also edit the corresponding statement in the statement table.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.