question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom NLU Components Failed to find component class

See original GitHub issue

Rasa version: 0.14

Rasa X version (if used & relevant):

Python version: 3.6

Operating system: Ubuntu

Issue: I’m trying to make own Custom NLU Components, but rasa_nlu can’t find my component, probably I miss something

rasa_nlu : 
├── classifiers
│   ├── ....
├── emulators
│   ├── ...
├── extractors
│   ├── ...
├── featurizers
│   ├── ...
├── schemas
│   └── ...
├── tokenizers
│   ├── ...
├── training_data
│   ├── ...
├── utils
│   ├── ...
│
│ 
├── customcomponents
│   ├── __init__.py
│   └── sentiment.py
│
│
├── __init__.py
├── registry.py
├── config.json
│
│
├── components.py
├── config.py
├── convert.py
├── data_router.py
├── evaluate.py
├── model.py
├── persistor.py
├── project.py
├── run.py
├── server.py
├── train.py
└── version.py

My Custom component sentiment.py :


from rasa_nlu.components import Component
# all import needed

class MySentimentAnalyzer(Component):
    """A pre-trained sentiment component"""

    name = "MySentimentAnalyzer"
    provides = ["entities"]
    requires = ["tokens"]
    defaults = {}
    language_list = ["en"]

    def __init__(self, component_config=None):
        super(MySentimentAnalyzer, self).__init__(component_config)

  ## THE REST OF CODE ...

registry.py :


from rasa_nlu.customcomponents.sentiment import MySentimentAnalyzer
# all import needed

component_classes = [
#
# all rasa components added no change
#
MySentimentAnalyzer
]

## THE REST OF COD

Error (including full traceback):

{
  "error": "Failed to find component class for 'customcomponents.sentiment.MySentimentAnalyzer'. 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."
}

Command or request that led to error: (Python)


requests.post(
                url='http://0.0.0.0:5000/train',
                params = (('project', PROJECT_NAME), ('model', MODEL_NAME)),
                headers = {'content-type': 'application/x-yml'},
                data = data
            )

Content of configuration file (config.json) (if relevant):

{
   "language":"pl",
   "pipeline":[
      {
         "name":"tokenizer_whitespace"
      },
      {
         "name":"customcomponents.sentiment.MySentimentAnalyzer"
      },
      {
         "name":"ner_duckling_http",
         "locale":"pl_Pl",
         "url":"http://127.0.0.1:8000",
         "dimensions":[
            "time",
            "number",
            "money"
         ]
      }
   ]
}

NEED HELP :

in config file try different combinations, still rasa can’t find my component 😕 any ide wht’s wrong ??

Content of configuration file (config.json) which I try :

  • name:“customcomponents.sentiment.MySentimentAnalyzer”
  • name:“sentiment.MySentimentAnalyzer”
  • name:“.MySentimentAnalyzer”

All of them don’t work for me 😕

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
elyasecommented, Jun 8, 2019

The error message can be misleading. You will see the same error if your component fails to import for any reason i.e. missing dependencies, has any syntax or other error you might have in your custom component or component not in your PYTHONPATH. I had to fix all these three issues to get it working:

To debug try:

❯ python                                                                                                                     
>>> import importlib;importlib.import_module('your_custom_component')

Also check that you can import any dependencies you declared in required_packages . For example if your required_packages looks like:

    @classmethod
    def required_packages(cls) -> List[Text]:
        return ["nltk"]

check that you can import nltk.

Finally make sure that your component is in the PYTHONPATH (ex: export PYTHONPATH=.). It is not enough to have it on the root folder of the project. For some reason rasa doesn’t look there at least if you use the new cli (rasa train).

Related issues: https://github.com/RasaHQ/rasa/issues/3552 https://github.com/RasaHQ/rasa/issues/1513

1reaction
mjspeckcommented, Jun 4, 2019

I’ve had a similar problem. The path to my sentiment analyzer is this: nlu.custom_components.sentiment.SentimentAnalyzer, but when I run rasa train I get this error:

Exception: Failed to find component class for 'nlu.custom_components.sentiment.SentimentAnalyzer'.
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.

I haven’t added the directory to my Python path, but I shouldn’t need to do that, right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom NLU Components Failed to find component class
Issue: I'm trying to make own Custom NLU Components, but rasa_nlu can't find my component, probably I miss something
Read more >
rasa - rasa_nlu: Failed to find component class, unknown ...
I don't have any custom components - I'm only using the standard pipeline. Exception: Failed to find component class for 'WhitespaceTokenizer'.
Read more >
Hi! Thanks for the tutorial.. Exception: Failed to find component…
Hi! Thanks for the tutorial. I have created the sentiment.py file in the main project directory and added sentiment.
Read more >
Oracle Digital Assistant Known Issues - Cloud
If there are files in that directory structure that aren't custom components, the upload process fails because it can't parse the file as...
Read more >
Advance Rasa: NLU Pipelines and more - Turtle-Techies
Custom NLU pipeline Components. Rasa NLU permits making a custom Component to play out a particular task which NLU doesn't presently offer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found