Handling Dates in Rasa Action

Hi Folks,

I am trying to extract the date from the user input in my bot, for example:

U : What is the sales in the store1234 last year?

B : The total sales of the store1234 last year was 123456

In order to achieve this I have designed the bot with the intent - sales and entities : store_id , date.

For handling date I have used duckling as well, so the the values are getting extracted properly but since there is only the initial value of date when the user query by last year. It assign the date entity as 01-01-2017. I am trying to calculate the last date using the duckling which gives the additional information as ‘grain’ : ’ year '. So using this I can calculate my date2 as date1 + 364 .

I am trying to handle these in my custom action file. I am able to retrieve the date slot value which is just the 01-01-2017.

How can I solve this problem?

Any help would be really appreciated.

Thanks,

Neel

@souvikg10 : I request you to help me in this!

Sorry but I don’t understand what you want here? You want the date of last year?

I want the dates of last year. For example someone asked " What is my total.sales in last year?" So for calculating the total sales I need both the dates i.e 01-01-2017 and 31-12-2018.

One way ,I thought to do it using a little hack. Since duckling give me information about grain like day, week, month, quarter and year. So I would calculate the end date by adding corresponding days for week, month, quarter and year in the first date!

Let me know how to achieve this. And if you have better approach kindly share and how to implement as well!

Looking forward for your reply.

Thanks, Neel

You are right, though the query should really be at your database side to be able to find all sales data in the year 2017.

Duckling also provides range so if someone asks “what are my total sales between february and september last year”. (try this out)

you can use grain to construct a default date pattern or use SQL query to generate date as well. if you receive a value let’s say 2017, you can use it to generate a query to retrieve all sales in 2017.

Thanks for quick reply! But where to handle these in the code? I am using a date entity and same as slot. In custom action I am getting the slot value but I am not sure how to get grain value as well from duckling!!!

Help me with the coding prospect.

Just for curiosity,can I use jupyter notebook for the whole.development as I am developing everything in simple notepad++ editor and executing by terminal. But if I could run these in jupyter notebook I could see the intermediate steps as well!

@souvikg10: I am sharing the structure of my bot

Domain FIle

** Action File **

So if you can see in my domain file I have entity ans wel as the slot of date. Now I am trying to extract the date and pass that date to the action file as of now I have put only one date in the action file sql query! But going ahead I want to calculate the both the dates as I mentioned earlier.

Kindly help what to do here!

I would also like to ask, how to take the duckling value ( since it has the information about the grain as well) in the slot or during the action file?

I would also like to know how to see or interact with the values what slot has picked, so I can cross check and do the changes! As of now I could see it only in the online training that what the slot has picked with a particular question asked. For example in the below pic:

I can see that the slot has value yesterday but I need the date actually. I am getting the time value fromm the duckling I guess but I am not able to use it!

Kindly help! Stuck at this point!

Thanks,

Neel

Okay

Your duckling entity name is time not date. You should name your slot time instead

1 Like

@souvikg10 Thanks for your reply! I am working using time as slot. I want to ask is there a way to work on the action file in an interactive way like using jupyter notebook, since I am unaware what the slot has soted the value and the its type. Once I train the bot using train_init.py and then train_online.py then only I come to know what is happening. If there could be another way to woark n action file in interactive way things would be easy to debug.

I think you can use Jupyter notebook with rasa. You will need to use the tracker API to extract conversation information including what intent is caught for the last message and what entities are extracted, there you will find the grain of the entity time extracted by ner_duckling_http

http://rasa.com/docs/core/api/tracker/

@souvikg10 Hey I am using the time entity and it is able to fetch the values but I have another problem now, since it is not giving any information about the grain value so to understand the interval like year or month is problem . I am sharing the output what I am getting from the tracker.get_slot(‘time’)

U - what is sales in store1234 from 01-01-2018 to 02-01-2018
time slot  - {'to': '2018-02-02T00:00:00.000-08:00', 'from': '2018-01-01T00:00:00.000-08:00'}`

U -  What is sales last month
time slot -  2018-07-01T00:00:00.000-07:00

If we will get the grain value then we would be able to calculate the second/ last day of the interval.

Let me know if I am missing while capturing the slot value.

Kindly help.

Thanks in advance.

Neel

Got something really interesting just now! https://github.com/RasaHQ/rasa_core/issues/429

I think it will work!

3 Likes

Thanks I was looking at a similair problem :+1: