Search code examples
pythonnlpspacy

Load custom trained spaCy model


I am trying to load a spaCy text classification model that I trained previously. After training, the model was saved into the en_textcat_demo-0.0.0.tar.gz file.

I want to use this model in a jupyter notebook, but when I do

import spacy
spacy.load("spacy_files/en_textcat_demo-0.0.0.tar.gz")

I get

OSError: [E053] Could not read meta.json from spacy_files/en_textcat_demo-0.0.0.tar.gz

What is the correct way to load my model here?


Solution

  • You need to either unzip the tar.gz file or install it with pip.

    If you unzip it, that will result in a directory, and you can give the directory name as an argument to spaCy load.

    If you use pip install, it will be put with your other libraries, and you can use the model name like you would with a pretrained spaCy model.