Wav2Vec2ForCTC and Wav2Vec2Tokenizer

Having installed transformers and trying:

import transformers
import librosa
import soundfile as sf
import torch
from transformers import Wav2Vec2ForCTC
from transformers import Wav2Vec2Tokenizer

#load model and tokenizer
tokenizer = Wav2Vec2Tokenizer.from_pretrained(“facebook/wav2vec2-base-960h”)
model = Wav2Vec2ForCTC.from_pretrained(“facebook/wav2vec2-base-960h”)

I get:

ImportError Traceback (most recent call last)
3 import soundfile as sf
4 import torch
----> 5 from transformers import Wav2Vec2ForCTC
6 from transformers import Wav2Vec2Tokenizer

ImportError: cannot import name ‘Wav2Vec2ForCTC’ from ‘transformers’ (c:\python\python37\lib\site-packages\transformers_init_.py)

How I install/get Wav2Vec2ForCTC and Wav2Vec2Tokenizer ???

This probably means you don’t have the latest version. You should check your version of Transformers with

import transformers

and if you don’t see at least 4.3.0, you will need to upgrade your install.

1 Like

I have the same issue with Windows 10.

pip install transformers[torch]==4.3

import transformers
from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC
Traceback (most recent call last):
File “”, line 1, in
ImportError: cannot import name ‘Wav2Vec2ForCTC’

1 Like

I had the same issue. I upgraded the transformers version from 4.3.0 to 4.3.2 with
pip install transformers==4.3.2
and that worked for me. Also, upgrade your PyTorch to its latest version 1.7 with
pip install torch==1.7
that avoids error while loading pre-trained weights in the next step.


use " from transformers import *" instead of “from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC”

1 Like