# Implementing TFIDF as a custom component?

**URL:** <https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032>\
**Category:** Rasa Open Source\
**Created:** [March 13, 2020, 9:55am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032 "2020-03-13T09:55:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ActuallyAcey](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/actuallyacey/32/6644_2.png) [@ActuallyAcey](https://forum.rasa.com/u/ActuallyAcey)\
**Post date:** [March 13, 2020, 9:55am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032/1 "2020-03-13T09:55:16Z")

</div>

Hi.

As part of a project at work, I’m building a bot that can answer a predefined set of FAQs. Given the large volume of questions we have, writing training data for them all (including implementation with RasaX) will take a lot of time.

I’ve found that some simple tf-idf vectorization produces really good results for answering FAQs that are similar but have entirely unique answers. Eg.   
  
`What is an escrow account?`   
`What is an escrow cushion?`  
  
Yields a very accurate result in TFIDF (given how it’s designed to focus on unique words, of course) but requires a substantial amount of training data to make Rasa differentiate between the two acceptably.

I’ve read the tutorial on designing custom components, but there doesn’t seem to be a way to really approach this particular problem.

How should I approach this?

---

<div class="post-metadata">

**Author:** ![ActuallyAcey](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/actuallyacey/32/6644_2.png) [@ActuallyAcey](https://forum.rasa.com/u/ActuallyAcey)\
**Post date:** [March 23, 2020, 9:43am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032/2 "2020-03-23T09:43:15Z")

</div>

Anything on this, guys?

---

<div class="post-metadata">

**Author:** ![NoahDrisort](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noahdrisort/32/9951_2.png) [@NoahDrisort](https://forum.rasa.com/u/NoahDrisort)\
**Post date:** [July 2, 2020, 10:06am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032/3 "2020-07-02T10:06:45Z")

</div>

I also think TF-IDF is suitable in this case, Have you solve this problem I am going to use sklearn library but don’t know how to apply it in sparse\_featurize folder

---

<div class="post-metadata">

**Author:** ![ActuallyAcey](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/actuallyacey/32/6644_2.png) [@ActuallyAcey](https://forum.rasa.com/u/ActuallyAcey)\
**Post date:** [July 2, 2020, 11:29am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032/5 "2020-07-02T11:29:20Z")

</div>

I wasn’t able to find a “clean” solution for this, so what I did was generalize all my FAQ data into one intent (or several, if you have sections). I then used a custom action to route the user’s message to a separate Python module that runs a normal TF-IDF search and responds with the results.

---

<div class="post-metadata">

**Author:** ![NoahDrisort](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/noahdrisort/32/9951_2.png) [@NoahDrisort](https://forum.rasa.com/u/NoahDrisort)\
**Post date:** [July 6, 2020, 3:51am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032/6 "2020-07-06T03:51:25Z")

</div>

Are your both action in parallel like RASA, I mean the classifier and the action selector in TF-IDF ?

I don’t know how to seperate which featurizer for each:

- Countvector ngram -\> DIET classifier
- TF-IDF -\> Default Reponse selector of RASA is it available parallel in RASA

I am going to share the custom tf-idf when i finish it

---

<div class="post-metadata">

**Author:** ![ActuallyAcey](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/actuallyacey/32/6644_2.png) [@ActuallyAcey](https://forum.rasa.com/u/ActuallyAcey)\
**Post date:** [July 6, 2020, 6:57am UTC](https://forum.rasa.com/t/implementing-tfidf-as-a-custom-component/26032/7 "2020-07-06T06:57:31Z")

</div>

No, they’re sequential. Its really just one custom action, but it sends the message to a different app entirely to do the TF-IDF processing and which sends back a response.
