Custom components value return

In my chatbot I have a list of stop words. So I build a custom component to to filter these stop word. But I’m sure how to return filtered message from custom component.

Config.yml

  • name: “SpacyNLP”
  • name: “SpacyTokenizer”
  • name: “custom_components.stop_word.StopWordDeductor”
  • name: “SpacyFeaturizer” return_sequence: true
  • name: “RegexFeaturizer”
  • name: “CRFEntityExtractor”
  • name: “EntitySynonymMapper”
  • name: “SklearnIntentClassifier”

Custom Component file:

class StopWordDeductor(Component):
name = "stopword_deductor"
provides = ["tokens"]
requires = ["spacy_doc"]

def __init__(self, component_config=None):
    super(StopWordDeductor, self).__init__(component_config)

def process(self, message, **kwargs):

    unfiltered_message = str(message.text)

    print(unfiltered_message)

    stop_words = ["a", "b", "c", "d"]
    # meassge_tokens = word_tokenize(message)
    message_tokens = list(unfiltered_message.split(" "))
    print(message_tokens)
    filtered_word_list = [w for w in message_tokens if not w in stop_words]
    filtered_message = ' '.join([str(element) for element in filtered_word_list])

    print(filtered_message)

    message.text = filtered_message
    print(message.text)

    return message

def persist(self, file_name, model_dir):
    """Pass because a pre-trained model is already persisted"""
    pass

So, here my stop words are a, b, c, d; if user message contains any of these token that’s should be filtered out, which is actually working in process function. But in chatbot backend I found:

rasa.core.processor - Received user message ‘some_text_input_by_user’,

this some_text_input_by_user is the message which I’m trying to filter. I did filtering but not able to return that to next component, cause rasa.core.processor is showing some_text_input_by_user without filtering.

What I’m missing here?

Your user literally enters some_text_input_by_user. The stop words in your component are a, b, c, d.

Since your example message does not contain the tokens a, b, c, d the SpacyFeaturizer would receive some_text_input_by_user and the pipeline would continue. Did you want to add some_text_input_by_user as a stop word along with a, b, c, d?