# Prodigy with AllenNLP model

**URL:** https://support.prodi.gy/t/prodigy-with-allennlp-model/3947
**Category:** Uncategorized
**Tags:** usage, allennlp
**Created:** [February 26, 2021, 7:24am UTC](https://support.prodi.gy/t/prodigy-with-allennlp-model/3947 "2021-02-26T07:24:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![other](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@other](https://support.prodi.gy/u/other)
#### Post date: [February 26, 2021, 7:24am UTC](https://support.prodi.gy/t/prodigy-with-allennlp-model/3947/1 "2021-02-26T07:24:24Z")

</div>

Hello,  
I have an existing NER model trained using AllenNLP and I'd like to use it in the ner.correct recipe. I've seen previous posts here on integrating custom models by jamming them into a SpaCy pipeline. What wasn't clear to me is how prodigy knows to use it for NER... is it by naming it "ner" or is it by virtue of the model being last in the pipeline? Should the model **call** return a spacy.token.Doc object with ents attached to it or can it just output a list of dictionaries for Prodigy to be able to use those outputs in the labeling task?

Thanks.

---

<div class="post-metadata">

### Author: ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)
#### Post date: [February 26, 2021, 11:58pm UTC](https://support.prodi.gy/t/prodigy-with-allennlp-model/3947/2 "2021-02-26T23:58:00Z")

</div>

Hi! You don't have to integrate your AllenNLP model into spaCy to use it with Prodigy – you can also just run it directly in a custom Prodigy recipe and use it to pre-set the `"spans"` in the data. Here's an example that shows pretty much exactly what you're looking for: [Named Entity Recognition · Prodigy · An annotation tool for AI, Machine Learning & NLP](https://prodi.gy/docs/named-entity-recognition#custom-model) The only part you have to plug in is the part that runs your model over a text and outputs the detected entities. [See hrere](https://prodi.gy/docs/api-interfaces#ner_manual) for the full JSON format – that's what your stream needs to send out if you want to annotate with the `ner_manual` interface. But everything else is up to you 🙂

Wrapping other models as spaCy components can often be useful because it gives you a single unified API for your NLP pipeline. So you can write your code to expect the `Doc` object data structure as the "single source of truth". But as I said, it's certainly not a must for Prodigy. For completeness, to clarify the other questions:

> [@other](#):
>
> What wasn't clear to me is how prodigy knows to use it for NER... is it by naming it "ner" or is it by virtue of the model being last in the pipeline?

Prodigy will source the entities it suggests from the `doc.ents` – it's agnostic to how they got there. Typically, the entity recognizer would be the component in the pipeline setting those annotations, but they could also come from a rule-based component (e.g. spaCy's `EntityRuler`) or something entirely custom.

---

<div class="post-metadata">

### Author: ![other](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@other](https://support.prodi.gy/u/other)
#### Post date: [March 2, 2021, 7:38am UTC](https://support.prodi.gy/t/prodigy-with-allennlp-model/3947/3 "2021-03-02T07:38:17Z")

</div>

That's really helpful, thank you! This is definitely easier than a custom pipeline component. A custom Prodigy recipe makes sense for this case. I think I'd also like to be able to use the `ner.teach` recipe to update this AllenNLP model I have. Could you point me to the API I should expose in my custom model in order make use of this? Thanks again.

On an unrelated note, the two ExplosionAI products I've interacted with so far, SpaCy and Prodigy are fantastic!

---

<div class="post-metadata">

### Author: ![ines](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ines/32/3_2.png) [@ines](https://support.prodi.gy/u/ines)
#### Post date: [March 4, 2021, 1:25am UTC](https://support.prodi.gy/t/prodigy-with-allennlp-model/3947/4 "2021-03-04T01:25:11Z")

</div>

Thanks, that's nice to hear!

Here are some examples of custom Prodigy recipes with custom models in the loop: [Named Entity Recognition · Prodigy · An annotation tool for AI, Machine Learning & NLP](https://prodi.gy/docs/named-entity-recognition#custom-model) There are essentially two parts your recipe needs to return: a `stream` of examples to annotate (a generator, so the suggestions can change as the model is updated) and an `update` callback that receives answers and updates the model. The specifics here depend on your model implementation: you want to choose a model that is sensitive enough to small updates in small batches, but also not _too_ sensitive so a single decision won't throw it off. This may take some experimentation.

Also, here are some related recent threads on similar topics:

> [@active learning and update function](https://support.prodi.gy/t/active-learning-and-update-function/3938/2):
>
> Hi! The update callback is called by Prodigy whenever a batch of examples comes back from the web app. It receives a list of annotated examples in Prodigy's JSON format – so basically whatever was sent out via the stream, with the added annotations (e.g. manually added spans) and the "answer". See here for the API docs: [https://prodi.gy/docs/custom-recipes#update](https://prodi.gy/docs/custom-recipes#update) Prodigy's binary annotation recipes use a more complex annotation model (e.g. the EntityRecognizer class implemented by Prodigy) to…

> [@Custom recipe to teach a DistilBERT model with custom labels](https://support.prodi.gy/t/custom-recipe-to-teach-a-distilbert-model-with-custom-labels/3827/3):
>
> Hi! We don't currently have an NER implementation that uses transformer weights in spaCy v2.x, so your approach wouldn't work – but once [spaCy v3](https://nightly.spacy.io/usage/v3) is out, we'll have an updated version of Prodigy that will let you use transformer-based pipelines, pipelines with custom models in PyTorch/TF and pretty much everything else that spaCy v3 offers. (The error you came across here btw looks like a different problem: internally, the NER annotation model deepcopies/pickles the nlp object and it looks like…
