Training preparation steps
Before and during training of a spaCy
model, you'll need to (1) disable other pipeline components in order to only train the intended component and (2) convert a Doc
container of a training data point and its corresponding annotations
into an Example
class.
In this exercise, you will practice these two steps by using a pre-loaded en_core_web_sm
model, which is accessible as nlp
. Example
class is already imported and a text
string and related annotations
are also available for your use.
This exercise is part of the course
Natural Language Processing with spaCy
Exercise instructions
- Disable all pipeline components of the
nlp
model exceptner
. - Convert a
text
string and itsannotations
to the correct format usable for training.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
nlp = spacy.load("en_core_web_sm")
# Disable all pipeline components of except `ner`
other_pipes = [____ for ____ in nlp.____ if ____ != 'ner']
nlp.____(*other_pipes)
# Convert a text and its annotations to the correct format usable for training
doc = nlp.____(text)
example = Example.____(____, ____)
print("Example object for training: \n", example.to_dict())