Can not import pipeline from transformers

Viewed 14239

I have installed pytorch with conda and transformers with pip.

I can import transformers without a problem but when I try to import pipeline from transformers I get an exception:

from transformers import pipeline
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-69a9fd07ccac> in <module>
----> 1 from transformers import pipeline

ImportError: cannot import name 'pipeline' from 'transformers' (C:\Users\Alienware\Anaconda3\envs\tf2\lib\site-packages\transformers\__init__.py)

This is a view of the directory where it searches for the init.py file:

enter image description here

What is causing the problem and how can I resolve it?

3 Answers

Check transformers version. Make sure you are on latest. Pipelines were introduced quite recently, you may have older version.

It is announced at the end of May that spacy-transformers v0.6.0 is compatible with the transformers v2.5.0. So, if you planning to use spacy-transformers also, it will be better to use v2.5.0 for transformers instead of the latest version.

So, try;

pip install transformers==2.5.0

pip install spacy-transformers==0.6.0

and use 2 pre-trained models same time without any problem

Related