davidberenstein1957 / classy-classification

This repository contains an easy and intuitive approach to few-shot classification using sentence-transformers or spaCy models, or zero-shot classification with Huggingface.
MIT License
209 stars 15 forks source link

ImportError: cannot import name 'cached_path' from 'transformers.file_utils' (/opt/conda/lib/python3.7/site-packages/transformers/file_utils.py) #24

Closed brownyaroundtown closed 1 year ago

brownyaroundtown commented 1 year ago

When trying to import the module after pip install classy-classifier in a new venv I get this import error consistently when trying 'import class_classification' after 'import spacy'

Full Error Text

ImportError Traceback (most recent call last) /tmp/ipykernel_31548/4164985023.py in ----> 1 import classy_classification

/opt/conda/lib/python3.7/site-packages/classy_classification/init.py in 3 from spacy.language import Language 4 ----> 5 from .classifiers.sentence_transformer import ( 6 classySentenceTransformer as classyClassifier, 7 )

/opt/conda/lib/python3.7/site-packages/classy_classification/classifiers/sentence_transformer.py in 4 from onnxruntime import InferenceSession, SessionOptions 5 from transformers import AutoTokenizer ----> 6 from txtai.pipeline import HFOnnx 7 8 from .classy_skeleton import classySkeleton

/opt/conda/lib/python3.7/site-packages/txtai/pipeline/init.py in 11 from .image import 12 from .nop import Nop ---> 13 from .text import 14 from .tensors import Tensors 15 from .train import *

/opt/conda/lib/python3.7/site-packages/txtai/pipeline/text/init.py in 10 from .similarity import Similarity 11 from .summary import Summary ---> 12 from .translation import Translation

/opt/conda/lib/python3.7/site-packages/txtai/pipeline/text/translation.py in 13 from huggingface_hub.hf_api import HfApi 14 from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer, MarianMTModel, MarianTokenizer ---> 15 from transformers.file_utils import cached_path 16 17 from ..hfmodel import HFModel

tomaarsen commented 1 year ago

Hello!

cached_path was removed from transformers.file_utils with this PR:

Please see the following issue for details on the issue in txtai:

In particular:

The workaround for txtai < 5.0 is to pin transformers to <= 4.21.3.

Also, I think you may be using an older classy_classification version, is that possible?

davidberenstein1957 commented 1 year ago

@tomaarsen thanks! I dropped support for 3.7 for some reason so it is an older version. I need to take a closer look at the dependencies.

brownyaroundtown commented 1 year ago

Thank you, both - will test again now with a new Python environment and pin Transformers to <= 4.21.3 to see if I can get things working and close out the issue after the test.