# SentimentAnalyzer

**URL:** <https://forum.rasa.com/t/sentimentanalyzer/4981>\
**Category:** Rasa Open Source\
**Created:** [February 7, 2019, 10:59am UTC](https://forum.rasa.com/t/sentimentanalyzer/4981 "2019-02-07T10:59:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![FiorenzoParascandolo](https://avatars.discourse-cdn.com/v4/letter/f/6a8cbe/32.png) [@FiorenzoParascandolo](https://forum.rasa.com/u/FiorenzoParascandolo)\
**Post date:** [February 7, 2019, 10:59am UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/1 "2019-02-07T10:59:32Z")

</div>

[SentimentAnalyzer.py](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/8/88a9ab06699e019a82c9f0cd42549d918e0482e6.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”

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [February 20, 2019, 12:52pm UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/2 "2019-02-20T12:52:24Z")

</div>

Hey @FiorenzoParascandolo. We have just posted [a tutorial](https://medium.com/rasa-blog/enhancing-rasa-nlu-models-with-custom-components-6f54040c4a77) on custom components. Check it out and let me know if you are still facing the issues.

---

<div class="post-metadata">

**Author:** ![FiorenzoParascandolo](https://avatars.discourse-cdn.com/v4/letter/f/6a8cbe/32.png) [@FiorenzoParascandolo](https://forum.rasa.com/u/FiorenzoParascandolo)\
**Post date:** [February 22, 2019, 10:16am UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/3 "2019-02-22T10:16:47Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [February 22, 2019, 12:16pm UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/4 "2019-02-22T12:16:21Z")

</div>

@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`

---

<div class="post-metadata">

**Author:** ![FiorenzoParascandolo](https://avatars.discourse-cdn.com/v4/letter/f/6a8cbe/32.png) [@FiorenzoParascandolo](https://forum.rasa.com/u/FiorenzoParascandolo)\
**Post date:** [February 26, 2019, 12:58pm UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/5 "2019-02-26T12:58:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FiorenzoParascandolo](https://avatars.discourse-cdn.com/v4/letter/f/6a8cbe/32.png) [@FiorenzoParascandolo](https://forum.rasa.com/u/FiorenzoParascandolo)\
**Post date:** [February 26, 2019, 1:31pm UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/6 "2019-02-26T13:31:39Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [February 26, 2019, 4:24pm UTC](https://forum.rasa.com/t/sentimentanalyzer/4981/7 "2019-02-26T16:24:59Z")

</div>

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` .
