# Pass custom features to CRFEntityExtractor

**URL:** <https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107>\
**Category:** Rasa Open Source\
**Created:** [August 8, 2019, 2:58pm UTC](https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107 "2019-08-08T14:58:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesmf](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/jamesmf/32/4476_2.png) [@jamesmf](https://forum.rasa.com/u/jamesmf)\
**Post date:** [August 8, 2019, 2:58pm UTC](https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107/1 "2019-08-08T14:58:38Z")

</div>

A thing that seems like it would add a lot of out-of-the-box power to custom entity recognizers is the ability to pass token-level features to `CRFEntityExtractor` (previously `ner_crf`).

The simplest version of this would be a `SpacyEntityFeaturizer` that would make a token’s `.vector` attribute available to `CRFEntityExtractor`. That would let you use much more powerful features in classifying your custom entities than simply part-of-speech or the other current features.

I am working on a way to add this feature and would love comments/feedback/confirmation that others want this feature.

> <https://github.com/RasaHQ/rasa/pull/4187>
>
> This is a work-in-progress implementation that allows custom entity-featurizers …to pass features along to \`CRFEntityExtractor\`. This would enable new featurizers that passed word/token vectors along to \`CRFEntityExtractor\`. Also following this \`ner\_features\` pattern would make it easy to develop other components that could also do custom NER. 
> 
> The edit to the example is just to show that, while the \`DummyNERFeaturizer\` provides nothing but noise to the \`CRFEntityExtractor\`, it seems to be working.
> 
> Just looking for feedback before I add tests or do much else.
> 
> Addresses https://forum.rasa.com/t/feeding-custom-pretrained-embeddings-for-ner-crf/5406
> 
> \*\*Proposed changes\*\*:
> \- Make \`CRFEntityExtractor\` look for \`ner\_features\` on the message
> \- Have \`CRFEntityExtractor\` convert the features from an array to \`python-crfsuite\` style dicts
> 
> \*\*Status (please check what you already did)\*\*:
> \- \[X\] made PR ready for code review
> \- \[x\] added some tests for the functionality
> \- \[x\] updated the documentation
> \- \[x\] updated the changelog
> \- \[X\] reformat files using \`black\` (please check \[Readme\](https://github.com/RasaHQ/rasa\_nlu#code-style) for instructions)

---

<div class="post-metadata">

**Author:** ![Ghostvv](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ghostvv/32/211_2.png) [@Ghostvv](https://forum.rasa.com/u/Ghostvv)\
**Post date:** [August 9, 2019, 2:59pm UTC](https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107/2 "2019-08-09T14:59:47Z")

</div>

Thank you for proposing this idea. Did you perform any comparison experiments to analyze the performances?

---

<div class="post-metadata">

**Author:** ![jamesmf](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/jamesmf/32/4476_2.png) [@jamesmf](https://forum.rasa.com/u/jamesmf)\
**Post date:** [August 9, 2019, 5:12pm UTC](https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107/3 "2019-08-09T17:12:14Z")

</div>

still brainstorming that. Are there any standard datasets where this would be helpful?

The restaurantbot or something similar?

---

<div class="post-metadata">

**Author:** ![jamesmf](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/jamesmf/32/4476_2.png) [@jamesmf](https://forum.rasa.com/u/jamesmf)\
**Post date:** [August 11, 2019, 10:00pm UTC](https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107/4 "2019-08-11T22:00:26Z")

</div>

Here we go, updated the PR with the results from a `rasa test nlu`.:

> <https://github.com/RasaHQ/rasa/issues/4214>
>
> \*\*Description of Problem\*\*:
> Right now custom entities can only use \`pos\` featur…es from \`spacy\` and a handful of simple features. This seems to be in contrast to the flexibility and power of the other pipeline components which can take advantage of any combination of built-in and custom \`featurizers\`. Ideally, there would be a way to pass \`ner\_features\` to the \`CRFEntityExtractor\`. In particular, this would let you train NER that used word/token vectors straight from spacy (or other pretrained models)
> 
> \*\*Overview of the Solution\*\*:
> \- \`CRFEntityExtractor\` needs to additionally check for \`ner\_features\` on the message and add them to the feature dict it passes to \`sklearn\_crfsuite\`.
> \- There need to be NER featurizer classes added
> 
> \*\*Examples\*\* (if relevant):
> The skeleton of this (both adding a \`spacy\`-based featurizer and making \`CRFEntityExtractor\` use \`ner\_features\`) is implemented in this PR
> https://github.com/RasaHQ/rasa/pull/4187
> Please let me know if this looks like a useful feature and if this PR is heading in the right direction.
> 
> Still necessary:
> \- Add tests
> \- Extend \`Featurizer\` to also have \`\_combine\_with\_existing\_ner\_features\` 
> \- Validate that having default spacy tokens noticeably improves NER for a sample task
> \- Make \`spacy\` only optionally add to \`ner\_features\`
> \- Replace the hard-coded lambda functions in \`CRFEntityExtractor\` with a simple \`Featurizer\`
> 
> 
> \*\*Definition of Done\*\*:
> \<!-- What needs to be there to consider this feature as done?
> \- \[\] Tests are added
> \- \[\] Feature described the docs
> \- \[\] Feature mentioned in the changelog

---

<div class="post-metadata">

**Author:** ![Ghostvv](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ghostvv/32/211_2.png) [@Ghostvv](https://forum.rasa.com/u/Ghostvv)\
**Post date:** [August 12, 2019, 1:11pm UTC](https://forum.rasa.com/t/pass-custom-features-to-crfentityextractor/14107/5 "2019-08-12T13:11:28Z")

</div>

thanks a lot! Let’s move the discussion to this PR. Our team will review it as soon as possible
