导入错误:无法从“transformers.utils”导入名称“_LazyModule”

问题描述 投票:0回答:1

我正在尝试运行文本摘要“t5-base”模型。该代码在我第一次运行时可以工作,但在安装/重新安装一些软件包后,它不再工作。谁能告诉我如何解决这个问题? ??

这是我的代码:

import torch
from transformers import AutoModel, AutoTokenizer 

tokenizer = AutoTokenizer.from_pretrained('t5-base')
model = AutoModelWithLMHead.from_pretrained('t5-base', return_dict=True)

inputs = tokenizer.encode("summarize: " + text,
                          return_tensors='pt',
                          max_length=512,
                          truncation=True)
summary_ids = model.generate(inputs, max_length=150, min_length=80, length_penalty=5., num_beams=2)
text = tokenizer.decode(summary_ids[0])
text = text.replace("<pad>","").replace("</s>","")
text

以下是我收到的错误消息:

    ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-46-2c9eeafa599f> in <module>
      1 import torch
----> 2 from transformers import AutoModel, AutoTokenizer

~/opt/anaconda3/lib/python3.7/site-packages/transformers/__init__.py in <module>
     29 # Check the dependencies satisfy the minimal versions required.
     30 from . import dependency_versions_check
---> 31 from .utils import (
     32     _LazyModule,
     33     is_flax_available,

ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/Users/sangjinlee/opt/anaconda3/lib/python3.7/site-packages/transformers/utils/__init__.py)
python nlp pytorch huggingface-transformers
1个回答
0
投票

我也遇到同样的问题,请问你解决了吗? 谢谢你。

© www.soinside.com 2019 - 2024. All rights reserved.