I am building a Chinese chatbot for rasa
How can I make rasa read the answers in the csv?
My csv file looks like this:
question,answer
q1,answer1
q2,answer2
q3,answer3
β¦
When I said q1, let rasa answer answer 1
I am building a Chinese chatbot for rasa
How can I make rasa read the answers in the csv?
My csv file looks like this:
question,answer
q1,answer1
q2,answer2
q3,answer3
β¦
When I said q1, let rasa answer answer 1
Note: your excel file should have two fields i.e question | answer or what response you want to return but should be synchronized and even it should have variations of the question with answers.
@dan246 updated code on 23-Nov-2021
Please see this
class GetAnswer(Action):
def __init__(self):
self.faq_d = pd.read_csv('./data/faq_d.csv')
qs = list(self.faq_d['question'])
with open("./data/nlu/faq.yml", "wt", encoding="utf-8") as f:
f.write('version: "2.0"\n')
f.write("nlu: \n- intent: question\n examples: | \n")
for q in qs:
f.write(f" - {q}\n")
return []
When the above piece of code fetches the data i,e question part and make the faq.yml file of that data which you want to train and then later it will go into the second code thatβs FuzzyWuzzy and then return your response. For me, itβs a clean process, but yes you need to fine-tune. Do try this code and search the FuzzyWuzzy process.
The advantage of this process is just added and run and that in excel/csv.
I hope this will solve your query and give you idea. Good Luck!
ok
let me try
thanks!!
@dan246 No worries, any time you are stuck please do tag me @ and nik202. I know you can do it. Good Luck!
@nik202 Hi, should I put the program in actions.py?
Because I noticed that there is a code similar to transcoding
which means I donβt need to fill in each piece of data with nlu, or do I need to set something?
@dan246 yes you need to mention the code in action.py as it and try run you will able to see the file. in data.
I am now extracting the data in the csv file like this:
(csv data)
use python to output οΌ
Then put it in rasa for training
@dan246 I will recommend to create a proper question answers ie.
file name for this is faq_d.csv
question |answer
How we can install rasa and rasa x | Please visit this link for installation Installation Guide How are the different types of slots | Domain
etc etc
When you run the above custom code, it will create the faq.yml file in the data folder which we will used to train our mode as we do manually and then you need a fuzzywuzzy logic to fetch the answers.
Confirm me:
Iβd would recommend to first do this process which I mentioned.
@dan246 can you explain more what you actually want?
The code I suggested will only create the intent and training examples, it will not create the domain and stories data.
@nik202 What could we do to let the robot answer the question beyond the data we input though it had not be trained before, even if the answer is not correct at all
I know fuzzywuzzy, itβs hard for me, but I want to do it well
(Second, the third sentence has not been trained, so the robot did not answer)
the robot canβt answer the qustion beyond its content and trainig examples. If it encounters the condition mentioned above, it just answer nothing. I hope it could answer the question beyond its content and trainig examples, even if the answer isnβt correct .
@dan246 how bot will answer the question which not reside in database (.csv) or training examples?
I dnt know your language.
I not get you what you try to do? and is code running which I suggested? Please confirm me that first.
@nik202 I put it in actions.py and trained rasa, but he did not run out of faq.yml
Do i need to add something else?
@dan246 dan I thought you will mention this in action.py mate?
Update code on 23-Nov-2021 @dan246
class GetAnswer(Action):
def __init__(self):
self.faq_d = pd.read_csv('./data/faq_d.csv')
qs = list(self.faq_d['question'])
with open("./data/nlu/faq.yml", "wt", encoding="utf-8") as f:
f.write('version: "2.0"\n')
f.write("nlu: \n- intent: question\n examples: | \n")
for q in qs:
f.write(f" - {q}\n")
def name(self) -> Text:
return "action_get_answer"
return []
and you need to mention action_get_answer
in domain.yml too?
I can share you complete code and with running commands but it will kill your learning bro.
Try this please and then do let me know.
Hope you willl understand this. Thanks.
@nik202 hi,Iβm sorry for the late response.
I tried the above method but still canβt succeed
I tried rasa shell and he ran the following error
I checked rasa run actions
I tried to find a solution by myself but failed
Can you tell me how to improve? thank you
@dan246 Dan check the indentation, can you put 1 space before
def name(self) -> Text:
It should be alined with above def
Try
@nik202 Good afternoon, it ran out of new errors
Is my file format wrong?Or am I not setting it somewhere?
@dan246 I have shared you everything bro, please share me the code again or just copy and paste it action.py file which I wrote and just run rasa run actions.
@nik202 sorry
My csv data looks like this
domain
Where do I need to add anything (ex. nlu or stories)
@dan246 send me your action.py file, your .csv file.