Transformer: cannot import name 'AutoModelWithLMHead' from 'transformers'

5.1k views Asked by At

I was referring to this answer from stackoverflow but I can't get any leads regarding my problem: [https://stackoverflow.com/questions/63141267/importerror-cannot-import-name-automodelwithlmhead-from-transformers][1]

This is the code that I ran:

import transformers
from transformers import AutoModelWithLMHead

Results:

cannot import name 'AutoModelWithLMHead' from 'transformers' (/Users/xev/opt/anaconda3/lib/python3.7/site-packages/transformers/__init__.py)

My transformer version is '3.0.2'. My import for AutoTokenizer is fine.

Would appreciate if there's anyone who can help regarding the Transformers package! [1]: ImportError: cannot import name 'AutoModelWithLMHead' from 'transformers'

2

There are 2 answers

0
AlbertoAndreotti On

Please try,

from transformers.modeling_auto import AutoModelWithLMHead
0
Dinesh On

just make sure you installed the transformers using its official git link

pip install git+https://github.com/huggingface/transformers

and not by using pypi

pip install transformers

coz there are few sub-libraries such as TFLayoutLMForSequenceClassification missing in pypi transformers version