SentimentAnalyzer

SentimentAnalyzer.py (7.2 KB)

Hello! I’m developing the SentimentAnalyzer component with a lexicon-based approach but I’m having problems.

  1. It is not clear to me how the components of the pipeline exchange messages. I would like my component to receive a tokenized text (if a POS component existed, even if already tagged) and I can not manage this. In the pipeline chain, should my component be preceded by a component that outputs a tokenized text? if this is true which component?
  2. the output of my component is a pair (string, float) representing the polarity of the text, placing my component last in the pipeline chain how do I view the final result of the computation?

(The future library is missing from the code due to an upload error.)

This is my pipeline chain:

language:“en”

pipeline: name:“nlp_spacy” name:“tokenizer_spacy” name:“SentimentAnalyzer.SentimentAnalyzer”

Hey @FiorenzoParascandolo. We have just posted a tutorial on custom components. Check it out and let me know if you are still facing the issues.

Hi. when I try to insert the component in my custom pipeline I have the following errors:

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 61, in EmbeddingIntentClassifier, SentimentAnalyzer NameError: name ‘SentimentAnalyzer’ is not defined

I’ve already tried to add the component name in the list to registry.py This is my pipeline: language: “en”

pipeline: name:“nlp_spacy” name:“tokenizer_spacy” name:“SentimentAnalyzer.sentiment”

@FiorenzoParascandolo to reference you custom component in the NLU pipeline you should use the following format: file_name.CustomComponentClassName. So for example, if the code of your custom component is in the file called sentiment.py and your custom component class is called SetnimentAnalyzer, then inside the NLU pipeline configuration file you should add sentiment.SentimentAnalyzer

I did well as you say but it does not change anything

I created a SentimentAnalyzer.py file; the name of the component is: “sentiment”; I added my component to the list of components in registry.py and in the pipeline I have: language: “en” pipeline: - name: “nlp_spacy” - name: “tokenizer_spacy” - name: “SentimentAnalyzer.sentiment” now I have the error: Traceback (most recent call last): File “C: /Users/39392/PycharmProjects/starter-pack-rasa-nlu-master/training.py”, line 9, in <module> 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 67, in <module> 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 67, in <dictcomp> registered_components = {c.name: c for c in component_classes} AttributeError: module ‘SentimentAnalyzer’ has no attribute ‘name’

Hey @FiorenzoParascandolo. As I understand your custom component class is also called SentimentAnalyzer. In that case, in your pipeline config file, you should reference it as SentimentAnalyzer.SentimentAnalyzer,

When referencing custom components you should use the following format: file_name.CustomComponentClassName .