Home > Software design >  OSError: [E053] Could not read meta.json from model-best.zip
OSError: [E053] Could not read meta.json from model-best.zip

Time:01-30

I tried to load the trained spacy model but this error appear:

OSError: [E053] Could not read meta.json from model-best.zip

this is my code:

nlp_ner = spacy.load("model-best.zip")

CodePudding user response:

For spaCy 3, you can load models from 3 sources:

Usually, any of these models is stored as a folder or directory, with an structure similar to this one (for a NER model, which it seems it is what you are attempting to load):

/path/to/your/model/
├── model-best  <== THIS DIRECTORY IS WHAT YOU MIGHT HAVE
│   ├── config.cfg
│   ├── meta.json
│   ├── ner
│   │   ├── cfg
│   │   ├── model
│   │   └── moves
│   ├── tok2vec
│   │   ├── cfg
│   │   └── model
│   ├── tokenizer
│   └── vocab
│       ├── key2row
│       ├── lookups.bin
│       ├── strings.json
│       ├── vectors
│       └── vectors.cfg
└── model-last
    ├── config.cfg
    ├── meta.json
    ├── ner
    │   ├── cfg
    │   ├── model
    │   └── moves
    ├── tok2vec
    │   ├── cfg
    │   └── model
    ├── tokenizer
    └── vocab
        ├── key2row
        ├── lookups.bin
        ├── strings.json
        ├── vectors
        └── vectors.cfg

8 directories, 26 files

This discards "loading directly from a .zip file" as a valid option.

I think you may want to try the following:

  1. Try to unzip model-best.zip and see if you find a similar directory structure than the one shown above. If you are in a Linux-based system, here is how.
  2. If the previous structure is confirmed, then proceed with step 3, otherwise your file may be corrupted, or not a spaCy model as such, and you won't be able to load the model.
  3. Try nlp_ner = spacy.load("/path/to/your/model-best") (nlp_ner = spacy.load("./model-best") in your case) and see if it works.

Hope it helps.

  • Related