Custom component process runs multiple times even when input has not given

Hello I have created a custom pipeline for altering user message but even before user inputs something the function is getting called and ‘None’ gets saved in the message variable So any further actions prints into a result saying none cannot be …etc my rasa version is Rasa Version : 2.1.2 Rasa SDK Version : 2.1.2 Rasa X Version : None Python Version : 3.6.8 Operating System : Windows-10-10.0.19041-SP0 Can anyone suggest how should i move forward with this

My CustomComponent file pre-processing.py import typing from typing import Any, Optional, Text, Dict, List, Type

from rasa.nlu.components import Component from rasa.shared.nlu.training_data.message import Message

if typing.TYPE_CHECKING: from rasa.nlu.model import Metadata installed_languages = translate.get_installed_languages() translation_ar_en = installed_languages[1].get_translation(installed_languages[0])

class MyComponent(Component):

@classmethod
def required_components(cls) -> List[Type[Component]]:
    
    return []

defaults = {}

supported_language_list = None

not_supported_language_list = None

def __init__(self, component_config: Optional[Dict[Text, Any]] = None) -> None:
    super().__init__(component_config)



def process(self, message: Message, **kwargs: Any) -> None:
    mt = message.get("text")
    print(mt)
   
    
def persist(self, file_name: Text, model_dir: Text) -> Optional[Dict[Text, Any]]:
    """Persist this component to disk for future loading."""

    pass

@classmethod
def load(
    cls,
    meta: Dict[Text, Any],
    model_dir: Text,
    model_metadata: Optional["Metadata"] = None,
    cached_component: Optional["Component"] = None,
    **kwargs: Any,
) -> "Component":
    """Load this component from file."""

    if cached_component:
        return cached_component
    else:
        return cls(meta)

my config.yml language: en

pipeline: - name: pre-processing.MyComponent policies:

hi traaaaaans_message

2022-02-01 14:20:52 DEBUG rasa.core.processor - Received user message ‘hi’ with intent ‘{‘name’: None, ‘confidence’: 0.0}’ and entities ‘[]’

2022-02-01 14:20:52 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 4 events.

2022-02-01 14:20:52 DEBUG rasa.core.policies.memoization - Current tracker state: [state 1] previous action name: action_listen

2022-02-01 14:20:52 DEBUG rasa.core.policies.memoization - There is no memorised next action

2022-02-01 14:20:52 DEBUG rasa.core.policies.rule_policy - Current tracker state: [state 1] previous action name: action_listen

2022-02-01 14:20:52 DEBUG rasa.core.policies.rule_policy - There is no applicable rule.

2022-02-01 14:20:52 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_2_RulePolicy.

2022-02-01 14:20:52 DEBUG rasa.core.processor - Predicted next action ‘action_default_fallback’ with confidence 0.30.

2022-02-01 14:20:52 DEBUG rasa.core.processor - Policy prediction ended with events ‘[]’.

2022-02-01 14:20:52 DEBUG rasa.core.processor - Action ‘action_default_fallback’ ended with events ‘[<rasa.shared.core.events.UserUtteranceReverted object at 0x000001C73AC59860>]’.

2022-02-01 14:20:52 DEBUG rasa.core.processor - Predicted next action ‘action_listen’ with confidence 1.00.

2022-02-01 14:20:52 DEBUG rasa.core.processor - Policy prediction ended with events ‘[]’.

2022-02-01 14:20:52 DEBUG rasa.core.processor - Action ‘action_listen’ ended with events ‘[]’.

‘’‘2022-02-01 14:20:52 DEBUG rasa.core.lock_store - Deleted lock for conversation ‘a739c12567fa43ea88420976309e30ba’.’’’

This is the error i got when i ran rasa shell --debug I believe its something regarding policies So can anyone help me with that

your config does not contain any classifier.

if you just want the results for your component,

run

rasa shell nlu

pass a message and check what your custom components provides

No so i ran rasa shell --debug to understand whats going on I want it to work when i do rasa run --enable-api --cors “*” Also when you say i dont have a classifier So there are only 2 things in cofig pipeline and policy, right? So where does a classifier comes I also tried adding Ted policy and Rule policy separately and together to see if that helps but same issue

Hey sorry, it is quite hard to understand your question without formatted text.

could you please format the code using ```

also the same for your config.yml, you pasted only the config about your custom component

My config file doesnt contain anything else

Like its just that pipeline

Also i formatted my error text above i hope it will be convenient to you now|

and Thank you for just quick replies

that’s what i was saying…

you have two parts to Rasa

One that understands your text and one that replies

similarly your config is split in two parts

pipeline:
 - yourcustomComponent
 - Tokenizer
 - Featurizer
 - Classifier
policies
 - TED
 - Rule

you need to add the other components in the pipeline for the bot to understand text and provide intent and entities

policies consider these as input and provides you with actions to do or reply

in your logs the first line says

2022-02-01 14:20:52 DEBUG rasa.core.processor - Received user message ‘hi’ with intent ‘{‘name’: None, ‘confidence’: 0.0}’ and entities ‘[]’

This means that the pipeline did not understand your text since you didn’t provide anything except your custom component and your custom component if i see the code doesn’t do anything thus your policies failed since they depend on the output of the pipeline.

So please create a valid config.yml where you also provide the remaning components of your pipeline which is missing in the information you provided above.

then we can see what’s wrong

the default pipeline is disabled i think if you provide a custom component like that so you must specify the rest of the components as well

Hello so actually I removed my code from the config file just to pass the message and see if that works

Also i added Ted and Rule policy but it didnt make any change

Now initially when i was using the bot i had not input any of the tokenizer, featurizer and still it was working

so do u mean i must add all the other pipelines too?

initially there was no pipelines right. thus rasa went to use the default one. now since you have a custom component in your pipeline, rasa does not pick up the rest as default instead you must now explicitly provide all the other components

Hey , So i tried adding the other pipelines and policies and still it is the same problem

can you share your config again with everything that you have added and the logs in a formatted way please?

Thanks

language: en

pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See https://rasa.com/docs/rasa/tuning-your-model for more information.
  - name: pre-processing.MyComponent
  - name: WhitespaceTokenizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: char_wb
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 100
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
  # - name: FallbackClassifier
  #   threshold: 0.3
  #   ambiguity_threshold: 0.1

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
  - name: MemoizationPolicy
  - name: TEDPolicy
    max_history: 5
    epochs: 100
  - name: RulePolicy

is your pre-processing a module with the root package having init.py ?

I woud create a package(folder) called custom then place the pre-processing.py in it and add another init.py and write the component in pre-processing.py

in my config, i will refer it as custom.pre-processing.MyComponent so your component is recognised

can you also the formatted error logs again?

Thanks

Hey I have printed my pre-processing.py file bellow

import typing
from typing import Any, Optional, Text, Dict, List, Type

from rasa.nlu.components import Component
from rasa.shared.nlu.training_data.message import Message

if typing.TYPE_CHECKING:
    from rasa.nlu.model import Metadata
installed_languages = translate.get_installed_languages()
translation_ar_en = installed_languages[4].get_translation(installed_languages[0])

class MyComponent(Component):
    
    print(lang_choice,'language')
    name = "translation"
    
    @classmethod
    def required_components(cls) -> List[Type[Component]]:
        
        return []

    defaults = {}

    supported_language_list = None

    not_supported_language_list = None

    def __init__(self, component_config: Optional[Dict[Text, Any]] = None) -> None:
        super().__init__(component_config)

    

    def process(self, message: Message, **kwargs: Any) -> None:
        
        pass
        
    def persist(self, file_name: Text, model_dir: Text) -> Optional[Dict[Text, Any]]:
        """Persist this component to disk for future loading."""

        pass

    @classmethod
    def load(
        cls,
        meta: Dict[Text, Any],
        model_dir: Text,
        model_metadata: Optional["Metadata"] = None,
        cached_component: Optional["Component"] = None,
        **kwargs: Any,
    ) -> "Component":
        """Load this component from file."""

        if cached_component:
            return cached_component
        else:
            return cls(meta)

@HarshMagiya7 - I don’t think the problem is in your Python code

Could you please share the logs in a formatted manner about what is going wrong once you have placed the config

Also please make sure your Python package for custom component is placed in the correct folder