Get the name value into the actions.py


(Norman) #1

Hey there, How can I get from the rasa stack starterpack the value of the name example into the actions.py file? So I want to make a WeatherAction and when I say: “Tell me the current weather in London”, that he take the value “London” into the actions.py file.

best regards norman


(Steve) #2

Hi Norman,

You can use the get_latest_entity_values() method from the tracker to access the value(s) of a given entity from within your action’s run() method.

If you are using a spaCy pre-trained model, it handily pulls locations out into a GPE entity for you so you could do something like this…

class ActionWeather(Action):

    def name(self):
        return "action_weather"

    def run(self, dispatcher, tracker, domain):
        where = next(tracker.get_latest_entity_values('GPE'), None)
        if where is not None:
            dispatcher.utter_message("You asked about {}".format(where))
        else:
            dispatcher.utter_message("I couldn't tell where!")
        
        return []

Hope that helps!


(Norman) #3

I made it like you now, but he always say “I couldn’t tell where”. But I wrote also the city! That is my weather intent.

intent:weather


(Steve) #4

Ok, so that shows that the action server is working but you’ll need more training data to get the NLU reliably picking up the location entity. I suggest you add at least 20 more training examples and then re-train the NLU.


(Norman) #5

I have now 24 samples and my chatbot say just, that he dont know where. Dont know what I did wrong there


(Steve) #6

Are you using the Spacy pipeline, or something else?

Can you post a sample of your training data - it may be you are using a different entity name.


(Norman) #7

I use the spacy_sklearn pipeline and my sample of my weather intent in nlu_data.md is:

intent:weather

  • Tell me the weather in [Berlin] (weather)

  • What is the weather in [California] (weather)?

  • Say what in [Moskau] (weather) is the weather

  • [Hamburg] (weather) is the weather?

  • Tell me the temperature of [Bengasi] (weather)

  • Is in [Geldern] (weather) nice weather?

  • Tell me, what temperature is now in [Sachsen] (weather)

  • Is now a nice weather in [London] (weather) to make holidays?

  • What about [Johannesburg] (weather), is there a nice weather?

  • Is the temperature in [Hannover] (weather) high?

  • Is the temperature in [Straelen] (weather) low?

  • Is it cold in [Krefeld] (weather)?

  • Can you tell me, is it hot in [Florida] (weather) at the moment?

  • Can you tell me, is it hot in [Bengasi] (weather) at the moment?

  • Can you tell me, is it hot in [Mainz] (weather) at the moment?

  • Is now a nice weather in [Britain] (weather) to make holidays?

  • What about [Luxenburg] (weather), is there a nice weather?

  • Tell me the weather in [Orlando] (weather)

  • What is the weather in [Barcelona] (weather)?

  • Say what in [Canada] (weather) is the weather

  • [Bermuda] (weather) is the weather?

  • Is the temperature in [Panama] (weather) high?

  • Is the temperature in [Cuba] (weather) low?

stories.md:

story_weather

  • weather
  • action_weather

The action_weather is the same like what you wrote


(Steve) #8

In your training data, you have called the entity “weather”, but the action.py code is expecting it to be called “GPE”. Just changing the run method in the action.py code to read…

where = next(tracker.get_latest_entity_values('weather'), None)

…should fix that.

There’s documentation for the NLU markdown format here.

Personally, I find having the same name for the intent and the entity rather confusing. It’ is clearer if the entity is named after what it really represents. I think your training data is confusing as it is marking up the location (the city/place) and calling it “weather.”