# Translating recipe tags to a Spacy custom pipeline component

**URL:** <https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921>\
**Category:** Uncategorized\
**Tags:** usage, spacy, coref\
**Created:** [February 22, 2021, 1:32pm UTC](https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921 "2021-02-22T13:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalopey](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lalopey](https://support.prodi.gy/u/lalopey)\
**Post date:** [February 22, 2021, 1:32pm UTC](https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921/1 "2021-02-22T13:32:25Z")

</div>

I was wondering if there is some simple way to obtain the same tags provided by a Prodigy recipe through a custom pipeline component in Spacy? I'm guessing this is a process that happens under the hood in Prodigy.

For example, say I'd like to have a Spacy custom pipeline component that gave me the same initial tags that are given by, using one of your recipe examples,

> prodigy coref.manual coref\_movies en\_core\_web\_sm ./plot\_summaries.jsonl --label COREF

Thank you

---

<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 23, 2021, 11:21pm UTC](https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921/2 "2021-02-23T23:21:42Z")

</div>

Hi! I'm not 100% sure I understand the question correctly, do you have a more specific example? Do you want to train a pipeline component that assigns coreference relationships annotated in Prodigy?

---

<div class="post-metadata">

**Author:** ![lalopey](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lalopey](https://support.prodi.gy/u/lalopey)\
**Post date:** [February 25, 2021, 6:56am UTC](https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921/3 "2021-02-25T06:56:19Z")

</div>

Apologies if I wasn't clear! I'm trying to get the same exact tags through SpaCy Matcher to those provided by a prodigy recipe.

For example, in SpaCy I'm doing:

```
 nlp = spacy.load("en_core_web_lg")
 matcher = Matcher(nlp.vocab)
 pattern_np = [
             {"POS": "DET", "TAG": {"NOT_IN": ["PRP$"]}, "OP": "?"},
             {"POS": "ADJ", "OP": "*"},
             {
                 "POS": {"IN": ["PROPN", "NOUN"]},
                 "OP": "+",
                 "ENT_TYPE": {"NOT_IN": ["PERSON", "ORG"]},
             },
         ]
 pattern_prn = [{'POS':'PRON'}]
 
 matcher.add("NP", [pattern_np])
 matcher.add('PRN', [pattern_prn])

```

I copied the NP pattern from the recipes/coref.py file as suggested in another post.

Now for example:

```
 doc = nlp("Eddie fought the wild rabid wolves with Pickles the husky. He was a good boy.")
 
 matches = matcher(doc)
 for match_id, start, end in matches:
     string_id = nlp.vocab.strings[match_id] # Get string representation
     span = doc[start:end] # The matched span
     print(string_id, start, end, span.text)
 
 for ent in doc.ents:
   start = doc.ents[0].start
   end = doc.ents[0].end
   span = doc[start:end]
   print('ENT({})'.format(doc.ents[0].label_), start, end, ent)

```

Which gives me as output:

```
 NP 2 6 the wild rabid wolves
 NP 3 6 wild rabid wolves
 NP 4 6 rabid wolves
 NP 5 6 wolves
 NP 7 8 Pickles
 PRN 11 12 He
 NP 13 16 a good boy
 NP 14 16 good boy
 NP 15 16 boy
 ENT(PERSON) 0 1 Eddie

```

In here I notice that if there are nested NP spans, the NP that Prodigy gives me is the longest NP span (eg. the wild rabid wolves). Also, I might be missing some POS patterns that are not explicit in coref.py.

Ideally I'd like to have the exact Match patterns to those of a recipe like:

> prodigy coref.manual coref\_movies en\_core\_web\_lg ./plot\_summaries.jsonl --label COREF`

Which gives me:

 ![prod](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/9/9876c3e9d7726d81d02cb836cd2a9514ae7afc84.png)

So I was just wondering if there's some functionality to obtain the Matcher used in a recipe.

---

<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 25, 2021, 10:58am UTC](https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921/4 "2021-02-25T10:58:15Z")

</div>

Ahhh okay, thanks for the clarification! 👍

> [@lalopey](#):
>
> In here I notice that if there are nested NP spans, the NP that Prodigy gives me is the longest NP span (eg. the wild rabid wolves). Also, I might be missing some POS patterns that are not explicit in coref.py.

The pattern defined in `coref.py` is the only pattern used by the workflow. By default, the recipe also includes named entities (so everything in the `doc.ents`) and optionally, noun chunks (everything in `doc.noun_chunks`).

The [`filter_spans`](https://spacy.io/api/top-level#util.filter_spans) helper lets you filter a list of spans to only keep the (first) longest matches. This is also what Prodigy uses under the hood. Together, this should give you the same results as the coref recipe suggestion 🙂

---

<div class="post-metadata">

**Author:** ![lalopey](https://avatars.discourse-cdn.com/v4/letter/l/8dc957/32.png) [@lalopey](https://support.prodi.gy/u/lalopey)\
**Post date:** [February 25, 2021, 11:02am UTC](https://support.prodi.gy/t/translating-recipe-tags-to-a-spacy-custom-pipeline-component/3921/5 "2021-02-25T11:02:56Z")

</div>

Great, thank you!
