Rasa: No documentation on how to specify policies in a config file

Created on 4 Feb 2019  ·  7Comments  ·  Source: RasaHQ/rasa

Rasa Core version: 0.13.1

Python version: 3.6.6

Operating system (windows, osx, ...): OS X 10.14.2

Issue: There is no documentation on how to provide policies via a configuration file or how to feed this file to an Agent.

I can't figure a way to achieve this code with a configuration file:

agent = Agent('chat_domain.yml', policies = [MemoizationPolicy(), KerasPolicy()])

When I run this I get:

Exception: Passing policy configuration parameters to `agent.train(...)` is not supported anymore.

When I add a line to my chat domain, it has no effect. What is the correct thing here? I will add it to the docs if only someone will tell me. A google search hits nothing and fifteen minutes with the code yields nothing either.

Content of domain file (if used & relevant):

intents:
    - order_pizza
    - greet

entities:
    - size
    - toppings

slots:
    size:
         type: text
    toppings:
        type: text

templates:
    utter_greet:
        - 'Hello, how can I help you?'
        - 'Hi, I am here to help.'
    utter_get_pizza_size:
        - 'What pizza size?'
    utter_get_pizza_toppings:
        - 'What toppings would you like on your pizza?'
actions:
    - utter_greet
    - utter_get_pizza_size
    - utter_get_pizza_toppings
    - actions.ActionOrderPizza

policies:
    - 'KerasPolicy'
    - 'MemoizationPolicy'

All 7 comments

@rjurney please take a look at our docs here: https://rasa.com/docs/core/policies/#configuring-polices-using-a-configuration-file

@akelad I have. That is how I know this is missing: how to actually feed policies into an Agent is not in the documentation and I can't figure it out.

First I tried this, and it throws an error that specifying policies like this is no longer supported:

agent = Agent('config/chat_domain.yml', policies = [MemoizationPolicy(), KerasPolicy()])

Note that now my domain file config/chat_domain.yaml includes:

policies:
    - 'KerasPolicy'
    - 'MemoizationPolicy'

The file has no effect and it still says:

Exception: Passing policy configuration parameters to `agent.train(...)` is not supported anymore.

@akelad What am I missing in the documentation that addresses this problem?

passing a config file to the agent isn't supported, that's for the rasa_core.train script, the documentation I linked details how to pass policies to the Agent: https://rasa.com/docs/core/policies/#configuring-polices-in-code

If you really want to pass your yaml file to the polices, you have to use the config.load function first, like it's done here https://github.com/RasaHQ/rasa_core/blob/master/rasa_core/train.py#L172

I'm sorry but I'm confused. The pages that @akelad have linked in the documentation say to do exactly what @rjurney was doing.

* Configuring polices in code
You can pass a list of policies when you create an agent:

from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.agent import Agent

agent = Agent("domain.yml",
               policies=[MemoizationPolicy(), KerasPolicy()])

This does not work.

Trying the rasa_core.train script you mentioned also doesn't work:
python -m rasa_core.train -d domain.yml -s data/stories.md -o models/current/dialogue -c config.yml

That just directs me to use rasa train core, which does not have the same options, and I've got no reference to see if I'm doing it right or not.

Links reference in the comments don't have any information?
Can anyone direct me where can i get info?

try this way:

file train_initialialize.py

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from rasa_core import utils
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.policies.sklearn_policy import SklearnPolicy

if __name__ == '__main__':

    utils.configure_colored_logging(loglevel="DEBUG")

    training_data_file = './data/stories.md'
    model_path = './models/dialogue'
    agent = Agent("clio_domain.yml",policies=[MemoizationPolicy(max_history = 2), KerasPolicy()])

    training_data = agent.load_data(training_data_file)

    agent.train(training_data)

    agent.persist(model_path)

file config.yml

policies:
  - name: "KerasPolicy"
    featurizer:
    - name: MaxHistoryTrackerFeaturizer
      max_history: 5
      state_featurizer:
        - name: BinarySingleStateFeaturizer
  - name: "MemoizationPolicy"
    max_history: 5

run (in jupyter notebook, for example):

!python train_initialize.py -c config.yml

Was this page helpful?
0 / 5 - 0 ratings