# "Cannot deserialize model" error when loading retrained transformer model

**URL:** <https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774>\
**Category:** Uncategorized\
**Tags:** ner, done, spacy, transformers\
**Created:** [October 6, 2021, 6:07pm UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774 "2021-10-06T18:07:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yzzhong](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yzzhong](https://support.prodi.gy/u/yzzhong)\
**Post date:** [October 6, 2021, 6:07pm UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774/1 "2021-10-06T18:07:29Z")

</div>

Hi, I first trained a transformer model with the following, which successfully finished training.

> prodigy train prodigy/model/model\_100\_fulltext --ner train\_set\_full\_text --base-model en\_core\_web\_trf --eval-split 0.2

 ![image](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/0/043145f2d9e1de52f2bb3d7fd085d98c28f04285.png)

When I load the retrained model, I got the following error.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/6/6f54d2b850ae54faace748b142df7d1e706f6abc.png)

My spacy version is 3.1.3. prodigy version is 1.11.4.

---

<div class="post-metadata">

**Author:** ![adriane](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@adriane](https://support.prodi.gy/u/adriane)\
**Post date:** [October 7, 2021, 6:40am UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774/2 "2021-10-07T06:40:12Z")

</div>

Hi, I think this is the same issue as a known bug related to `spacy-transformers`: [PyTorchWrapper causes error on deserializing · Issue #8319 · explosion/spaCy · GitHub](https://github.com/explosion/spaCy/issues/8319)

We're working on a fix in `spacy-transformers`. If you are very adventurous, you can try out the current dev version: `pip install spacy-transformers==1.1.0.dev3`. We should be pretty close to the final release, but want to do a bit more testing first. If you do try it out, let us know how it goes!

---

<div class="post-metadata">

**Author:** ![adriane](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@adriane](https://support.prodi.gy/u/adriane)\
**Post date:** [October 22, 2021, 8:40am UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774/3 "2021-10-22T08:40:13Z")

</div>

Just a note that you can upgrade to a stable release now (currently v1.1.1):

```bash
pip install -U spacy-transformers

```

---

<div class="post-metadata">

**Author:** ![yzzhong](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yzzhong](https://support.prodi.gy/u/yzzhong)\
**Post date:** [October 26, 2021, 6:55pm UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774/4 "2021-10-26T18:55:02Z")

</div>

Hi, thanks for the update. I got some dependency issue when installing the new version. Any suggestions?

```python
en-core-web-trf 3.1.0 requires spacy-transformers<1.1.0,>=1.0.3, but you have spacy-transformers 1.1.1 which is incompatible.
```

---

<div class="post-metadata">

**Author:** ![adriane](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@adriane](https://support.prodi.gy/u/adriane)\
**Post date:** [October 28, 2021, 10:36am UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774/5 "2021-10-28T10:36:57Z")

</div>

The original `en_core_web_trf` v3.1.0 model is officially only compatible with `spacy-transformers>=1.0.3,<1.1.0`. v1.0.3 is the `spacy-transformers` version it was trained and tested with.

That said, we tried to make things as backwards compatible as possible and you should be able to load `en_core_web_trf` v3.1.0 with `spacy-transformers>=1.1.1` (or `>=1.1.2` for windows). You'll see a warning each time it's loaded, but it should still load and run normally. (If it doesn't, let us know!)

If you want to avoid the warning, you'd have to uninstall `en_core_web_trf` and load this model from a new path or package instead. `nlp.to_disk()` will save the converted model in the v1.1 format.

---

<div class="post-metadata">

**Author:** ![yzzhong](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yzzhong](https://support.prodi.gy/u/yzzhong)\
**Post date:** [November 2, 2021, 6:48pm UTC](https://support.prodi.gy/t/cannot-deserialize-model-error-when-loading-retrained-transformer-model/4774/6 "2021-11-02T18:48:07Z")

</div>

Thanks. I will try that. Is it possible to train the en\_core\_web\_trf in the PyTorch framework which I am more familiar? Is there any documentation on that?
