Transformers model from Hugging-Face throws error that specific classes couldn t be loaded
Asked Answered
M

3

19

Hi after running this code below, I get the following error.

ValueError: Could not load model facebook/bart-large-mnli with any of the following classes: (<class 'transformers.models.auto.modeling_tf_auto.TFAutoModelForSequenceClassification'>,).

import tensorflow as tf
from transformers import pipeline

classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")

Could someone please help. Thank you!

Malformation answered 7/1, 2022 at 14:43 Comment(0)
O
14

I had the same issue! Somebody has commented here that you need to have PyTorch installed (https://github.com/huggingface/transformers/issues/16849).

To sum it up:

  • Some models only exist as PyTorch models (e.g. deepset/roberta-base-squad2).
  • Calling pipeline() selects the framework (TF or PyTorch) based on what is installed on your machine (or venv in my case)
  • If both are installed, Torch will be selected
  • If you don't have PyTorch installed, it threw above mentioned error
  • Installing PyTorch solved the issue for me!
  • In the GitHub issue, another workaround is mentioned: load the model in TF with from_pt=True and save as personal copy as a TF model with save_pretrained and push_to_hub
Ogbomosho answered 26/4, 2022 at 17:47 Comment(1)
pytorch is already install, even then im getting this errorFaust
D
3

In my case, the problem was caused by very slow internet speed. Its worth noting that if keeps failing while download is in progress, you can retry till it works (hopefully).

Decern answered 26/12, 2022 at 17:22 Comment(1)
Surprised this hasn't been upvoted yet. Sometimes, the issue really is quite simple.Flagella
C
0

Use the following:

!pip install pytorch-pretrained-bert
import pytorch_pretrained_bert as ppb
assert 'bert-large-cased' in ppb.modeling.PRETRAINED_MODEL_ARCHIVE_MAP

Now run your original code.

Censorious answered 14/4, 2022 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.