Rasa: Cannot load custom component / custom IO channel by class name

Created on 10 Jun 2019  路  17Comments  路  Source: RasaHQ/rasa

I have a custom tokenizer and synonym mapper. It works fine on rasa core 0.14x and rasa nlu 0.15x.

I upgraded to rasa 1.0.8 and its not working anymore. It gives the followring error:

Exception: Failed to find component class for 'custom_components.synonym.DukaEntitySynonymMapper'. Unknown component name. Check your configured pipeline and make sure the mentioned component is not misspelled. If you are creating your own component, make sure it is either listed as part of the component_classes in rasa.nlu.registry.py or is a proper name of a class in a module.

Here is the pipeline that i'm using:

language: pt
pipeline:

  • name: "custom_components.tokenizer.DukaTokenizer"
  • name: CRFEntityExtractor
  • name: CountVectorsFeaturizer
  • name: EmbeddingIntentClassifier
  • name: "custom_components.synonym.DukaEntitySynonymMapper"
  • dimensions:

    • time

    • number

    • amount-of-money

    • distance

    • email

      locale: pt_BR

      name: DucklingHTTPExtractor

      timezone: "America/BrasxEDlia"

      url: http://localhost:8000

      policies:

  • batch_size: 50
    epochs: 200
    max_training_samples: 300
    name: KerasPolicy
  • fallback_action_name: action_default_fallback
    name: FallbackPolicy
  • max_history: 5
    name: MemoizationPolicy
  • name: FormPolicy
  • name: MappingPolicy

I've already tried adding the custom component folder with PYTHONPATH in ~/.bashrc, as suggested in https://github.com/RasaHQ/rasa/issues/3673

export PYTHONPATH="/home/bruno.roth/Documents/duka-data/nlu-data/custom_components"

But still no sucess.

area type

Most helpful comment

It worked!!

Thank you very much guys! Apparently everything is working correctly now.

All 17 comments

You can check out this issue for more details.

Or you can simply run it with python -m rasa train/run.

@BrunoRoth95 did that help?

Not really actually. I had read that issue before, and i've tried the python -m rasa train/run command as well as using conda develop <custom component directory>

Still the same error:

Exception: Failed to find component class for 'custom_components.synonym.DukaEntitySynonymMapper'. Unknown component name. Check your configured pipeline and make sure the mentioned component is not misspelled. If you are creating your own component, make sure it is either listed as part of the component_classes in rasa.nlu.registry.py or is a proper name of a class in a module.

@erohmensing can you look into this please?

Hey @BrunoRoth95, a couple questions. Are you running rasa locally or in docker? Is this issue just a rasa issue, not a rasa x one?

export PYTHONPATH="/home/bruno.roth/Documents/duka-data/nlu-data/custom_components"

To me, this looks like the custom_components folder isn't in your rasa project directory (but i'm not sure) -- what is your project dir, and have you tried putting the custom_components > synonym in there?

Hi @erohmensing! Thank you for your message. So, answering your first question, I'm running rasa locally, and this issue is just a rasa issue.

My custom_components folder contain 2 custom components, one tokenizer and one synonym mapper (sligthly modified version of the one available on rasa). This folder is located in my project directory (where the domain, actions, config files are).

I was able to fix the issue temporarily doing some hardcoding (which obviously is not a long-term solution). I've moved the custom_components folder to the rasa/nlu folder and added on the registry.py.

This also seems to happen for custom input / output channels according to @JustinaPetr

Might also be related to https://github.com/RasaHQ/rasa/issues/3673

I've also seen the same with custom policies. @tmbo any idea what may have changed such that this stuff can't be found? Maybe the fact that we're now training in temporary folders, so the paths don't work?

@erohmensing So what i think is happening is that importlib looks for the packages within PYTHONPATH. If my custom connector is somewhere else, it throws an error that the module doesn't exist. Adding the project dir to PYTHONPATH, for example:

export PYTHONPATH=/my_project_dir/:$PYTHONPATH

seems to solve the issue at least for my case, but it's a bit tedious approach

Yeah, that was @wochinge 's suggested approach, but it seems to work for some people and not others 馃the question is, what changed, since this wasn't a problem before?

@BrunoRoth95 Can you try running PYTHONPATH="/home/bruno.roth/Documents/duka-data/nlu-data/custom_components" rasa train ?

yeah this worked without the python path thing before...

Still not working...
Let me sum up what I did, so you guys can see if I'm doing something wrong:

1 - My project files (domain.yml, actions.py, config.yml, etc.) are now located at /home/bruno.roth/Documents/duka-data/duka-new

2 - Inside the duka-new folder I created a custom_components folder, where my two custom components are located (one tokenizer and one synonym mapper).

3 - I added the new components in my config.yml file as shown below:

pipeline:
- name: custom_components.tokenizer.DukaTokenizer
- name: CRFEntityExtractor
- name: CountVectorsFeaturizer
- name: EmbeddingIntentClassifier
- name: custom_components.synonym.DukaEntitySynonymMapper
(...)

4 - I edited sudo nano ~/.bashrc and added export PYTHONPATH=/home/bruno.roth/Documents/duka-data/duka-new/ at the bottom of the file.

Still the same error (even with @wochinge solution):

Exception: Failed to find component class for 'custom_components.tokenizer.DukaTokenizer'. Unknown component name. Check your configured pipeline and make sure the mentioned component is not misspelled. If you are creating your own component, make sure it is either listed as part of the component_classes in rasa.nlu.registry.py or is a proper name of a class in a module.

Do you also have __init__.py files in these directiories?

I think you also have to source the bashrc for the changes to take affect on your system:

source ~/.bashrc

You can also just quickly test it by simply running the following in your command line:

export PYTHONPATH=/home/bruno.roth/Documents/duka-data/duka-new/:$PYTHONPATH

Can try it and let me know if that works?

It worked!!

Thank you very much guys! Apparently everything is working correctly now.

Closing this for now, but we should update the docs with this too.

Was this page helpful?
0 / 5 - 0 ratings