# New entity model ruins other entities

**URL:** https://support.prodi.gy/t/new-entity-model-ruins-other-entities/179
**Category:** Uncategorized
**Tags:** solved, best-practices, ner
**Created:** [December 31, 2017, 12:31pm UTC](https://support.prodi.gy/t/new-entity-model-ruins-other-entities/179 "2017-12-31T12:31:27Z")
**Posts on this page:** 1
**Showing post:** 9

<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: [August 16, 2018, 3:19pm UTC](https://support.prodi.gy/t/new-entity-model-ruins-other-entities/179/9 "2018-08-16T15:19:20Z")

</div>

@Andrey A very simple solution would be to use spaCy, load the model you want to update later and process a bunch of sentences with it. You can then extract the existing entity spans, export them in the same format as your other annotations. Once you're done, mix in your new annotations and train the model on the complete data.

Here's a minimal example and implementation idea:

```python
nlp = spacy.load('en_core_web_sm')
examples = [] # save this out later

for doc in nlp.pipe(LIST_OF_YOUR_TEXTS):
    # get all existing entity spans with start, end and label
    spans = [{'start': ent.start_char, 'end': ent.end_char,
               'label': ent.label_} for ent in doc.ents]
    examples.append({'text': doc.text, 'spans': spans})

```

Of course, not all of the predictions are going to be correct, so you likely want to remove the bad ones. You could do this by hand or use Prodigy's `mark` recipe to just stream in the data and say yes or no to each span. So instead of creating one example with _all spans_, you could also create one example _per span_:

```python
for doc in nlp.pipe(LIST_OF_YOUR_TEXTS):
    for ent in doc.ents:
        span = {'start': ent.start_char, 'end': ent.end_char, 'label': ent.label}
        examples.append({'text': doc.text, 'spans': [span]})

```

Prodigy's `ner.make-gold` implements the same idea: you get to see what the model currently predicts _and_ you get to make edits and add new annotations. So your final training data will include both the new entities, as well as the old ones that the model previously got correct.

The training recipes in the latest version of Prodigy now also support a `--no-missing` flag that lets you specify that all annotations are complete and should be treated as gold standard. While the regular training process assumes that non-annotated tokens are missing values (to allow training from single entity spans and binary decisions), training with the `--no-missing` flag will treat all other tokens as `O` entities (outside an entity). So if you know that your training examples cover all entities that are present in the data, this can give you another boost in accuracy.

Finally, you might also find this thread useful, which discusses an approach to mix in examples from the model's original training data (in this case, spaCy's English models):

> [@Mixing in gold data to avoid catastrophic forgetting](https://support.prodi.gy/t/mixing-in-gold-data-to-avoid-catastrophic-forgetting/126):
>
> I have a question about how to best incorporate original training data to avoid catastrophic forgetting. I’ve been tweaking spaCy NER’s GPE tag to better pick up multi-word or hyphenated place names (which come up a lot in Spanish and Arabic names) and on some kinds of short text. After a thousand examples or so, the quality on those improves, but really falls apart on other place names. I’ve licensed the OntoNotes corpus and would like to be able to use its annotations to remind spaCy what othe…

---

_[View the full topic](https://support.prodi.gy/t/new-entity-model-ruins-other-entities/179)._
