I'm trying to access the trained neural network model used by the spaCy pipeline.
I can see from the spaCy documentation that the config.cfg specifies the model instance which is part of the pipeline, but I don’t understand how to access this model instance (data structure or its location) from within spaCy.
I'd like to access the model and its weights so I can use the neural network outside of spaCy. I was wondering if anyone had any pointers for accessing the Thinc pre-trained model?
CodePudding user response:
You can get the Model of a component like this.
import spacy
nlp = spacy.load("en_core_web_sm")
ner = nlp.get_pipe("ner")
model = ner.model
By convention, each component keeps its model (if present) in self.model
.
I'm not sure the model will be useful to you on its own though - models generally depend on the tok2vec they were with, and the tok2vec depends on the representation of lexemes in spaCy. So without the other parts of the pipeline you probably won't be able to get meaningful predictions.