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
14.07k stars 4.44k forks source link

Add an additional column to the default database table #1450

Closed Jereemi closed 5 years ago

Jereemi commented 6 years ago

I am trying to train multiple corpus, say for instance doctors corpus, faculties corpus and students corpus. This will train all the data and put it in the statement table one after the other. Is it possible to know if the statement is coming from which corpus?

I have thought of the approach but I am not sure if this is allowed in the default database created by chatterbot. Here is my approach: If I can create an additional column called TAGS in the statement table and label each statement as DOC for doctor corpus, STUD for student corpus, then querying the table as *select from statement where TAGS="DOC|STUD"**

@gunthercox Can you please suggest if this can be achieved?? Thanks!!

gunthercox commented 6 years ago

Hi @Jereemi, this is possible to do. I created a quick example using SQL queries to demonstrate it for you.

SELECT statement.id AS statement_id,
       statement.text AS statement_text,
       statement.conversation AS statement_conversation,
       tag.name
FROM   "statement"
       JOIN tag_association
         ON statement.id = tag_association.statement_id 
       JOIN tag 
         ON tag.id = tag_association.tag_id 
WHERE  tag.NAME IN ( "greetings", "trivia" )

This will return data in the following format:

statement_id statement_text statement_conversation tag_name
742 Very well, thanks. training greetings
768 The sky's up but I'm fine thanks. What about you? training greetings
743 How are you doing? training greetings
1386 Who was the 37th President of the United States? training trivia
1387 Richard Nixon training trivia
Jereemi commented 6 years ago

Hi @Jereemi, this is possible to do. I created a quick example using SQL queries to demonstrate it for you.

SELECT statement.id AS statement_id,
       statement.text AS statement_text,
       statement.conversation AS statement_conversation,
       tag.name
FROM   "statement"
       JOIN tag_association
         ON statement.id = tag_association.statement_id 
       JOIN tag 
         ON tag.id = tag_association.tag_id 
WHERE  tag.NAME IN ( "greetings", "trivia" )

This will return data in the following format:

statement_id statement_text statement_conversation tag_name 742 Very well, thanks. training greetings 768 The sky's up but I'm fine thanks. What about you? training greetings 743 How are you doing? training greetings 1386 Who was the 37th President of the United States? training trivia 1387 Richard Nixon training trivia

@gunthercox Thank you so much for the valuable answer. This means that I can create my own corpus and name it as doctors.yml (say) and use the above SQL query to extract the category statements. This is awesome. Thank you:D

Jereemi commented 6 years ago

@gunthercox In context to the above query, I have used the learn_new_response.py and the bot learns the new response but it won't give any tag_association with the newly learned statement.

So is there a way to tag the new statement without having to include it in the training file explicitly and re-train it?

gunthercox commented 6 years ago

The Statement objects that ChatterBot uses have an add_tags method that can be used to add one or more tags to a statement. Once the statement is saved, the tags will be created for it.

Jereemi commented 6 years ago

The Statement objects that ChatterBot uses have an add_tags method that can be used to add one or more tags to a statement. Once the statement is saved, the tags will be created for it.

@gunthercox Ok thank you for your suggestion. Then using this method can I approach it something like:

  1. First, I will make the user enter the name of the tag whenever they initiate a new chatbot.
  2. then after the user makes the chatbot learn many response, I will commit it into the database. Will this be a right approach?
gunthercox commented 6 years ago

@Jereemi That sounds correct to me :+1:

Jereemi commented 6 years ago

@Jereemi That sounds correct to me

@gunthercox Thank you so much:) I shall try the approach and update it here so that we can close the issue after its done.

Jereemi commented 6 years ago

@gunthercox I have tried the add_tags method, but I don't know why I am getting the error: AttributeError: 'StatementMixin' object has no attribute 'tags'

Here is how I wrote the code: from chatterbot.conversation import StatementMixin StatementMixin().add_tags('name-of-the-tag')

Can you please correct my mistake?

gunthercox commented 6 years ago

You'll need to use Statement instead of StatementMixin. The StatementMixin object is used to give various statement-like objects in ChatterBot the nessesary shared attributes but it is not intended to be used directly. More information on mixins can be found here: https://chrisbartos.com/articles/what-is-a-mixin/

lock[bot] commented 5 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.