# prodigy data-to-spacy for relation extraction

**URL:** <https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620>\
**Category:** Uncategorized\
**Tags:** ner, spacy, relations\
**Created:** [May 7, 2022, 7:08pm UTC](https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620 "2022-05-07T19:08:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nemomar](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/nemomar/32/2968_2.png) [@nemomar](https://support.prodi.gy/u/nemomar)\
**Post date:** [May 7, 2022, 7:08pm UTC](https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620/1 "2022-05-07T19:08:45Z")

</div>

First of all thanks for the excellent tool.

I want to convert my .jsonl file that contains annotated data to .spacy binary files for training a relation extraction (RE) model. I succeed to do it for the NER part with:

> prodigy data-to-spacy ./corpus\_ner --ner bla --eval-split 0.3 -V

but I cannot find the similar parameter (like "--ner") for RE.

Furthermore, I observed that in the case of the "--ner" parameter a config file was generated. Is the config file customized based on the input text (the .jsonl file) or is it a default one?

---

<div class="post-metadata">

**Author:** ![koaning](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/koaning/32/230_2.png) [@koaning](https://support.prodi.gy/u/koaning)\
**Post date:** [May 9, 2022, 7:16am UTC](https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620/2 "2022-05-09T07:16:24Z")

</div>

At the time of writing, spaCy doesn't natively support relation extraction models. The example that we list on our docs [here](https://spacy.io/usage/layers-architectures#component-rel) is meant to be a tutorial on how to set up a custom component, not a guide on a feature in spaCy.

The crux of the issue is that the `Doc` object in spaCy currently has no support for relationships. That is also why, in turn, the `.spacy` object does not support them.

The config file that you see can be changed via the `--config` flag ([docs](https://prodi.gy/docs/recipes#data-to-spacy)). If this flag is not set, which is your case, it will auto generate the default settings as found [here](https://spacy.io/usage/training).

---

<div class="post-metadata">

**Author:** ![nemomar](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/nemomar/32/2968_2.png) [@nemomar](https://support.prodi.gy/u/nemomar)\
**Post date:** [May 11, 2022, 8:30am UTC](https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620/3 "2022-05-11T08:30:12Z")

</div>

Thank you for your swift answer. Now I have a better image of what needs to be done. I have another question for you regarding the relation extraction models in spaCy.

Is it any limitation/recommendation regarding the training set (text length wise, relation length, relation between entities belonging to different sentences)? We obtained better results if the text has one sentence (this is also available for the example from spaCy). My interest is for extracting relations for entities that are in different sentences.

---

<div class="post-metadata">

**Author:** ![nlp\_reseracher478](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@nlp\_reseracher478](https://support.prodi.gy/u/nlp_reseracher478)\
**Post date:** [January 3, 2023, 2:48pm UTC](https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620/4 "2023-01-03T14:48:13Z")

</div>

Hi @nemomar !

I have a few questions hope you can answer.

1. Can you explain how you were able to address the issue?
2. For relationship extraction, we required a named entity as well, so do we need to run data-to-spacy two time one for ner and another for re or in the single pass it can be done?

---

<div class="post-metadata">

**Author:** ![ryanwesslen](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ryanwesslen/32/2969_2.png) [@ryanwesslen](https://support.prodi.gy/u/ryanwesslen)\
**Post date:** [February 23, 2023, 9:07pm UTC](https://support.prodi.gy/t/prodigy-data-to-spacy-for-relation-extraction/5620/5 "2023-02-23T21:07:34Z")

</div>

Thanks for your question!

> [@nlp\_reseracher478](#):
>
> - Can you explain how you were able to address the issue?
> - For relationship extraction, we required a named entity as well, so do we need to run data-to-spacy two time one for ner and another for re or in the single pass it can be done?

Sorry for the delay. Have you seen this post? You can modify [`parse_data.py`](https://github.com/explosion/projects/blob/v3/tutorials/rel_component/scripts/parse_data.py) from the [`rel_components`](https://github.com/explosion/projects/tree/v3/tutorials/rel_component) template project.

> [@data-to-spacy for rel\_component training](https://support.prodi.gy/t/data-to-spacy-for-rel-component-training/5852/4):
>
> Hi @korneliaB , Ok, let us step back for a bit. I realized that since you already have the labeled documents in Prodigy, you can export them into .jsonl using the [db-out command](https://prodi.gy/docs/recipes#db-out), then [reuse / modify this parse\_data.py script](https://github.com/explosion/projects/blob/v3/tutorials/rel_component/scripts/parse_data.py) to convert the JSONL files into the spaCy format. The reason why it errored out is because it expects some labels before the component is initialized. You can see this being done in the [main function](https://github.com/explosion/projects/blob/v3/tutorials/rel_component/scripts/parse_data.py#L22). So you have to do something like: python scripts.parse\_data path/to/js…
