Keyword based intent classification

I have about 2000 examples for around 40 intents, and they are generally working fine. Additionally I want to add a separate intent (an intent for using a general search engine) which is triggered when a certain keyword appears. I.e. I want my chatbot to work as usual with its robust NLU, but to be overriden if it recognizes a certain fixed pattern, and recognize all that follows this keyword as entities. This pattern is:

  • wyszukaj [keywords for the query](keywords)

I’m not sure how to proceed, because this is supposed to be a keyword, I cannot add much variation, and I am also not sure how to provide the examples of keywords, since they are supposed to be general (and thus can overlap with entities from other examples). Perhaps I should add a custom component?

Is KeywordClassifier what you are looking for?

To use this add the KeywordIntentClassifier to your pipeline after your main classifier, all intent examples will then be treated as keywords for their corresponding intents and if they are found in a message will result in the message automatically being classified as having that intent.

1 Like

Thanks. In the end I just wrote a custom component. Its quite a handy feature.

BTW, wouldn’t adding KeywordClassifier at the end of the pipeline be dangerous to more intricate nlu capabilities?

1 Like

Hi @ryszardtuora!

I think they can serve the “Forms” of Rasa.

https://rasa.com/docs/rasa/core/forms/#id1

Depends what you mean by dangerous. The KeywordIntentClassifier classifies a message if it found a keyword, putting it in the pipeline after another classifier would result in messages containing a keyword being classified based on keyword and the rest as normal.

Edit: Would you mind sharing your solution? I’d be interested to know what you did

In the end this custom component works better, as it imposes more rigid constraints (working by a regex which requires a certain ordering of the words, and also does automatic extraction of the search phrase). By the feature being handy, I meant the possibility of adding custom components.

init.py|attachment (3.0 KB)

3 Likes

Thank you @ryszardtuora, this helped.

Hello @ryszardtuora, sorry to reactivate old topic, but I’m wondering since I probably need to do the same as you, having pattern classifier intent together with normal ML intent classification. How does the intent class priority go if you use pattern classification together machine learning classifier?

Thank you @ryszardtuora because this help me a lot too.

Regarding your question @tomgun132 I put this custom classifier in the pipeline (of the config.yaml) after the DietClassifier, like this:

pipeline:

  • name: WhitespaceTokenizer
  • name: RegexFeaturizer
  • name: LexicalSyntacticFeaturizer
  • name: CountVectorsFeaturizer
  • name: CountVectorsFeaturizer analyzer: char_wb min_ngram: 1 max_ngram: 4
  • name: DIETClassifier random_seed: 42 epochs: 30 constrain_similarities: true
  • name: EntitySynonymMapper
  • name: nlu.classifiers._custom_keyword_classifier.KeywordMatching
  • name: FallbackClassifier threshold: 0.3 ambiguity_threshold: 0.1

Where KeywordMatching is my custom pattern detector based on @ryszardtuora proposal.