Unknown component name

I am trying to learn how to implement the sentiment analysis component following this tutorial: https://blog.rasa.com/enhancing-rasa-nlu-with-custom-components/

I created a file called sentiment.py and placed it in the root of my project folder.

I am getting this error:

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

If I add this to the bin/rasa file it works but that is not a good way to do it:

import sys

sys.path.append(“/Users/nickopris/Documents/work/rasax/bot”)

I understand that my new file is not visible to Rasa but I don’t know how to register it otherwise.

Full message below:

(venv) âžś  bot git:(master) âś— rasa train
2019-05-28 20:07:30 INFO     rasa.model  - Data (nlu-config) for NLU model changed.
Core stories/configuration did not change. No need to retrain Core model.
Training NLU model...
Traceback (most recent call last):
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/nlu/registry.py", line 141, in get_component_class
    return utils.class_from_module_path(component_name)
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/nlu/utils/__init__.py", line 140, in class_from_module_path
    m = importlib.import_module(module_name)
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sentiment'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/nickopris/Documents/work/rasax/venv/bin/rasa", line 10, in <module>
    sys.exit(main())
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/__main__.py", line 70, in main
    cmdline_arguments.func(cmdline_arguments)
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/cli/train.py", line 69, in train
    kwargs=extract_additional_arguments(args),
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/train.py", line 48, in train
    kwargs=kwargs,
  File "uvloop/loop.pyx", line 1451, in uvloop.loop.Loop.run_until_complete
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/train.py", line 144, in train_async
    kwargs=kwargs,
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/train.py", line 197, in _do_training
    fixed_model_name=fixed_model_name,
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/train.py", line 392, in _train_nlu_with_validated_data
    config, nlu_data_directory, _train_path, fixed_model_name="nlu"
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/nlu/train.py", line 83, in train
    trainer = Trainer(nlu_config, component_builder)
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/nlu/model.py", line 148, in __init__
    components.validate_requirements(cfg.component_names)
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/nlu/components.py", line 36, in validate_requirements
    component_class = registry.get_component_class(component_name)
  File "/Users/nickopris/Documents/work/rasax/venv/lib/python3.6/site-packages/rasa/nlu/registry.py", line 150, in get_component_class
    "in a module.".format(component_name)
Exception: Failed to find component class for '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.
2 Likes

Any ideas what I can do here?

I encountered the same problem, running python3 -m rasa train instead of rasa train helps me, but I think it is not the best solution.

1 Like

If someone have this issue, use this command

`export PYTHONPATH=/path_to_your_project_dir/:$PYTHONPATH`

path_to_your_project_dir - is the path to your sentiment.py file. This will solve the issue.

I have the same issue and I try this but doesn’t resolve the problem it still can’t find my component