Training your own NER model with spaCy
The NER model provided by spaCy can suffice in many cases. There might be other times, however, when we would like to augment the existing model or create a new one from scratch. spaCy has a toolset specifically for that, and in this recipe, we will do both.
Getting ready
We will use the spacy
package to train a new NER model. You do not need any other packages than spacy
.
How to do it…
We will define our training data and then use it to update an existing model. We will then test the model and save it to disk. The code in this recipe is based on the spaCy documentation (https://spacy.io/usage/training#ner). The steps for this recipe are as follows:
- Import the necessary packages:
import spacy from spacy.util import minibatch, compounding from spacy.language import Language import warnings import random from pathlib import Path
- Now we will define the training data that we will use:
DATA = [ ...