# Extending CRFEntityExtractor

**URL:** <https://forum.rasa.com/t/extending-crfentityextractor/762>\
**Category:** Rasa Open Source\
**Created:** [August 30, 2018, 9:17am UTC](https://forum.rasa.com/t/extending-crfentityextractor/762 "2018-08-30T09:17:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sam](https://forum.rasa.com/u/Sam)\
**Post date:** [August 30, 2018, 9:17am UTC](https://forum.rasa.com/t/extending-crfentityextractor/762/1 "2018-08-30T09:17:43Z")

</div>

Hello, I’m trying to add features to the ner\_crf. By looking at the source code i noticed that features are defined in ‘function\_dict’. To add to this dictionary additional features, I created a new component (called it Crf) which inherits from ‘crf\_entity\_extractor.CRFEntityExtractor’. Then I referenced this component in the rasa\_config.yml file. When I run the pipeline I notice that rasa\_nlu.extractors.crf\_entity\_extractor.CRFEntityExtractor is being called instead. Can you tell me what I might be doing wrong?

The custom component is:

```
class Crf(crf_entity_extractor.CRFEntityExtractor):
        function_dict = crf_entity_extractor.CRFEntityExtractor.function_dict

```

modifications on function\_dict are reflected on the process. For example, something like this would work

```
function_dict['email'] = lambda doc: True if '@' in doc[0] and '.' in doc[0] else False

```

However, if i attempt to override a method from CRFEntityExtractor (e.g. process, or \_from\_text\_to\_crf) in my custom class (Crf), the pipeline will still call these methods from CRFEntityExtractor. What can i do to fix this?

---

<div class="post-metadata">

**Author:** ![Oceania2018](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@Oceania2018](https://forum.rasa.com/u/Oceania2018)\
**Post date:** [August 30, 2018, 12:47pm UTC](https://forum.rasa.com/t/extending-crfentityextractor/762/2 "2018-08-30T12:47:38Z")

</div>

Are you doing predict?

---

<div class="post-metadata">

**Author:** ![Sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sam](https://forum.rasa.com/u/Sam)\
**Post date:** [August 30, 2018, 12:54pm UTC](https://forum.rasa.com/t/extending-crfentityextractor/762/3 "2018-08-30T12:54:29Z")

</div>

Sorry but I’m not following. Can you please elaborate?

---

<div class="post-metadata">

**Author:** ![Oceania2018](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@Oceania2018](https://forum.rasa.com/u/Oceania2018)\
**Post date:** [August 30, 2018, 1:01pm UTC](https://forum.rasa.com/t/extending-crfentityextractor/762/4 "2018-08-30T13:01:27Z")

</div>

Are you doing train or predict when you invoke your new pipeline. If predict, rasa will invoke the same pipeline with training at that moment. That’s why your new function isn’t be invoked.

---

<div class="post-metadata">

**Author:** ![Sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sam](https://forum.rasa.com/u/Sam)\
**Post date:** [August 30, 2018, 1:17pm UTC](https://forum.rasa.com/t/extending-crfentityextractor/762/5 "2018-08-30T13:17:58Z")

</div>

I first did train, then I loaded the trained model with RasaNLUInterpreter. When I called the parse method, in debugging mode, I noticed that it’s invoking CRFEntityExtractor and not my custom class, Crf.

---

<div class="post-metadata">

**Author:** ![Sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sam](https://forum.rasa.com/u/Sam)\
**Post date:** [August 31, 2018, 1:25pm UTC](https://forum.rasa.com/t/extending-crfentityextractor/762/7 "2018-08-31T13:25:28Z")

</div>

So basically i trained the model on my custom class (referenced in rasa\_config.yml) before invoking the predict function.

pipeline:

- name: “nlp\_spacy”
- name: “tokenizer\_spacy”
- name: “CustomExtractor.Crf”
- name: “intent\_featurizer\_count\_vectors”
- name: “intent\_classifier\_tensorflow\_embedding”

as you can see from the pipeline above, i referenced “CustomExtractor.Crf” before training the model. Yet, after training, the pipeline invokes “rasa\_nlu.extractors.crf\_entity\_extractor.CRFEntityExtractor” when i call the function model.parse(string)
