Enhacing Rasa NLU models with Custom Components - Getting Started with Rasa / Tutorials, Resources & Videos - Rasa Community Forum

Enhancing Rasa NLU models with Custom Components

Check out our latest tutorial on how to implement custom components and add them to your Rasa NLU pipeline! If you have added custom components to your Rasa NLU models, share your experience with us!

post by Juste on Feb 19, 2019

Enhancing Rasa NLU models with Custom Components


post by TatianaParshina on Feb 22, 2019

@Juste thank you for your post! It is really helpful!

I have a question. Is it possible to add a path to file with labels "labels.txt" to rasa_nlu.train command same as for "–data"? For example, add "–labels" option. Or is there another way to specify file path (not inside of the script)?


post by FiorenzoParascandolo on Feb 26, 2019

hi I created a SentimentAnalyzer.py file that contains the code of my custom component. I overridden the attributes

class SentimentAnalyzer (Component):

name = "sentiment"
    provides = ["entities"]
    requires = ["tokens"]
    defaults = {{}}

language_list = ["en"]

this is my pipeline: language: "en" pipeline:

this error appears to me: Traceback (most recent call last): File "C: /Users/39392/PycharmProjects/starter-pack-rasa-nlu-master/training.py", line 9, in trainer = Trainer (config.load ("nlu_config.yml")) File "C: \ Users \ 39392 \ AppData \ Local \ Programs \ Python \ Python36 \ Lib \ site-packages \ rasa_nlu \ model.py", line 152, in init components.validate_requirements (cfg.component_names) , File, "C: \ Users \ 39392 \ AppData \ Local \ Programs \ Python \ Python36 \ Lib \ site-packages \ rasa_nlu \ components.py", line 49, in validate_requirements from rasa_nlu import registry File "C: \ Users \ 39392 \ AppData \ Local \ Programs \ Python \ Python36 \ Lib \ site-packages \ rasa_nlu \ registry.py", line 65, in registered_components = {c.name: c for c in component_classes} File "C: \ Users \ 39392 \ AppData \ Local \ Programs \ Python \ Python36 \ Lib \ site-packages \ rasa_nlu \ registry.py", line 65, in registered_components = {c.name: c for c in component_classes} AttributeError: module ‘SentimentAnalyzer’ has no attribute ‘name’

why?


post by mohan on Mar 4, 2019

Hi @Juste,

Thank you so much for this tutorial, i was trying out this and got below error

File "C:\Users\ab56837\Desktop\ChatBot\New bot\Bot\sentiment_analysis.py", line 29, in train
with open('labels.txt', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'labels.txt'

I solved this error by using below code.

try:
        with open('labels.txt', 'r') as f:
            labels = f.read().splitlines()
    except:
        with open('labels.txt', 'w') as f:
            labels = f.write("")

now getting new error …

**File "C:\Users\ab56837\Desktop\ChatBot\New bot\Bot\sentiment_analysis.py", line 38, in train**
** labeled_data = [(t, x) for t,x in zip(processed_tokens, labels)]**
TypeError: zip argument #2 must support iteration

Please help me to implement this custom installation


post by Juste on Mar 6, 2019

Hey @mohan. The error says that you need a .txt file with in your working directory. This file, based on the example provided in a tutorial should contain sentiment labels for the NLU training examples you use to train the NLU model. A tiny snippet of how this file could look like is:

pos

pos

neu

neu

neg

neg

So, to replicate the provided example, you should create a label.txt file in your working directory and the sentiment labels for your NLU training examples. Give it a go and let me know if you still face issues.


post by iiemihai on Jun 1, 2019

Hello,

I have followed the tutorial on How to Enhance Rasa NLU Models with Custom Components | Rasa Blog | The Rasa Blog | Rasa and created a SentimentAnalyzer class and linked it in the config pipeline. When training the NLU module, the sentiment classifier is training, but when testing it does not output any sentiment label. My guess is that I have a wrong label.txt file format for my training dataset. I do not know the format of the label file that corresponds to a more complex training file. Please help me with the format of the labels.txt file.


post by BeWe11 on Jun 12, 2019

@Juste I wanna pick up a question that has been asked earlier but hasn’t been answered yet:

Is it possible to provide components with custom data without having to hardcode file paths into the component code? (Like the example does with the "labels.txt" file).

I have a custom component that reads extra fields defined in the JSON train files, but that’s hacky and doesn’t work properly in some cases. I think one way is to define paths in the config.yml file as component configs, but that turns the config from a static pipeline definition into a training-specific data definition. Is there a better way?


post by ikenti on Jun 26, 2019

Hi, The tutorial is very useful but I face a similar problem, and couldn’t solve it. I created a file sentiment.py in my project and added : - name: "sentiment.SentimentAnalyzer" to my pipeline. I also did "export PYTHONPATH=/path_to_your_project_dir/:$PYTHONPATH" but when I launch the training, I get that error message: “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.” Any idea? Thanks.