[SOLVED] Is it possible to set slot value from within stories file?

Suppose I have the following story inside my stories.md fil:

## say hello
* greet
  - utter_greet
  - utter_ask_name
* inform{"name":"John"}
  - set_user_name
  - utter_propose_help

Q1: I can write a custom action set_user_name where I programmatically can fill the slot name with user’s name. Isn’t it possible to do directly from stories.md?

Q2: Suppose I decided to fill slots from my code. The user my enter different text such as: My name is John, John, John Lennon, My friends call me John, etc. How do we extract the name John from the input. Do we have to extract, say, using spaCy, or is there any other RASA-way to perform this task? Assume I don’t use Python to process and my custom action is on another server.

So if both your entity and your slot have the same name, then the slot should get filled automatically. So yeah you’d use an entity extractor, you can use both ner_spacy or ner_crf for that.

It does not work. The following are my files:

domain.yml

entity:
  - name

slots:
  name:
    type: text

intents:
  - greet
  - goodbye
  - propose_help
  - inform

templates:
  utter_greet:
    - "hello"
  utter_goodbye:
    - "Goodbye"
  utter_ask_name:
    - "What is your name?"
  utter_propose_help:
    - "{name}, how can I help you?"

actions:
  - utter_greet
  - utter_goodbye
  - utter_ask_name
  - set_user_name
  - utter_propose_help

srories.md

## say hello
* greet
  - utter_greet
  - utter_ask_name
* inform{"name":"John"}
  - utter_propose_help

## say goodbye
* goodbye
  - utter_goodbye

nlu_config.md

language: "en"

pipeline:
- name: "nlp_spacy"
- name: "tokenizer_spacy"
- name: "intent_entity_featurizer_regex"
- name: "intent_featurizer_spacy"
- name: "ner_crf"
- name: "ner_synonyms"
- name: "intent_classifier_sklearn"

This is how I train NLU

from rasa_nlu.training_data import load_data
from rasa_nlu import config
from rasa_nlu.model import Trainer
from rasa_nlu.config import RasaNLUModelConfig

def train():
    trainer = Trainer(config.load('./nlu_config.md'))
    interpreter = trainer.train(load_data('./data/nlu.md'))
    model_directory = trainer.persist('./models/nlu/', fixed_model_name = 'simplebot')

if __name__ == '__main__':
    train()

It does not set the slot name. But when I add a custom action like this

* greet
  - utter_greet
  - utter_ask_name
* inform{"name":"Bayram"}
  - set_user_name
  - utter_propose_help

and set the name in the JSON response it works.

Then I added the following lines into my nlu.md file

## intent:inform
- My name is [John](name)
- My name is [Paul](name)

It fills the slot ‘name’ only when I enter My name is John and My name is Paul. What about other names? Or what if user simply enters John? Or what about other patters: Call me John? I guess I need provide more example to train it, almost every possible scenario?

I needed MORE!!! data, in particular more examples for nlu.md.

If you don’t have a source for alot of training data, I can recommend chatito. It’s a tool to generate nlu training data, which uses templates you define and then patching them together, with great documentation and support.

I was simply doing experiments trying to figure out how to use/fill slots. It turned out I need at least 10 NLU examples before the bot started to understand.

As for the chatito, an interesting project. I’ll have a look. Thank you for sharing.
:slight_smile:

1 Like

You should first look into your NLU data . Your NLU_MODEL isn’t strong enough to capture intent/entities of every string , i would suggest you exec you nlu model separately and try to add data so that it’s smart enough to classify intents and extract entities. After doing this move on to using it in your stories , that way you will have a systematic debugging

1 Like