Search code examples
pythonvisual-studio-codejupyter-notebookhuggingface-transformershuggingface-tokenizers

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


I am trying to fine tune Wav2Vec2 model for medical vocabulary. When I try to run the following code on my VS Code Jupyter notebook, I am getting an error, but when I run the same thing on Google Colab, it works fine.

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,
)

And here is the error that I getting on my 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'

Solution

  • Issue solved when I uninstalled both the libraries and installed their respective versions needed using following command:

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

    After this the issue got resolved.