AttributeError: type object 'Wav2Vec2ForCTC' has no attribute 'from_pretrained'

AttributeError: type object 'Wav2Vec2ForCTC' has no attribute 'from_pretrained'

我正在尝试微调医学词汇的 Wav2Vec2 模型。当我尝试在我的 VS Code Jupyter notebook 上 运行 以下代码时,出现错误,但是当我在 Google Colab 上 运行 同样的事情时,它工作正常。

from transformers import Wav2Vec2ForCTC
 
model = Wav2Vec2ForCTC.from_pretrained(
    "facebook/wav2vec2-base", 
    gradient_checkpointing=True, 
    ctc_loss_reduction="mean", 
    pad_token_id=processor.tokenizer.pad_token_id,
)

这是我在 VS Code 上遇到的错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-59-926a81051d7b> in <module>
      1 from transformers import Wav2Vec2ForCTC
      2 
----> 3 model = Wav2Vec2ForCTC.from_pretrained(
      4     "facebook/wav2vec2-base",
      5     gradient_checkpointing=True,

AttributeError: type object 'Wav2Vec2ForCTC' has no attribute 'from_pretrained'

当我使用以下命令卸载这两个库并安装它们各自所需的版本时,问题已解决:

pip uninstall huggingface-hub
pip uninstall transformers
pip install huggingface-hub==0.0.8
pip install transformers==4.6.1

此后问题得到解决。