# Fine tuning whisper for ASR

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-whisper-for-asr%2F46678%3E%5C
**Category:** Beginners\
**Created:** [July 13, 2023, 10:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-whisper-for-asr%2F46678 "2023-07-13T10:40:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhavychaudhary](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bhavychaudhary](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbhavychaudhary)%5C
**Post date:** [July 13, 2023, 10:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-whisper-for-asr%2F46678%2F1 "2023-07-13T10:40:52Z")

</div>

i’ve constantly been getting this error :  
OSError: Can’t load tokenizer for ‘facebook/wav2vec2-large-xlsr-53’. If you were trying to load it from ‘[Models - Hugging Face](https://huggingface.co/models)’, make sure you don’t have a local directory with the same name. Otherwise, make sure ‘facebook/wav2vec2-large-xlsr-53’ is the correct path to a directory containing all relevant files for a Wav2Vec2Tokenizer tokenizer.

I’ve made sure that i dont have a local dir with the same name as the tokenizer and have reinstalled the transformer.  
here’s the code :  
import torch  
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer  
from datasets import load\_dataset  
from transformers import TrainingArguments, Trainer, default\_data\_collator

model = Wav2Vec2ForCTC.from\_pretrained(“facebook/wav2vec2-large-xlsr-53”)  
tokenizer = Wav2Vec2Tokenizer.from\_pretrained(“facebook/wav2vec2-large-xlsr-53”)

dataset = load\_dataset(“common\_voice”, “hi”)  
def preprocess(example):  
speech, \_ = torchaudio.load(example[“path”])  
example[“speech”] = speech[0].numpy()  
return example

dataset = dataset.map(preprocess)

def tokenize(example):  
inputs = tokenizer(example[“speech”], return\_tensors=“pt”, padding=“longest”).input\_values  
example[“input\_values”] = inputs.squeeze()  
return example

dataset = dataset.map(tokenize, batched=True)

train\_dataset = dataset[“train”]  
test\_dataset = dataset[“test”]

training\_args = TrainingArguments(  
output\_dir=“./mymodel”,  
num\_train\_epochs=10,  
per\_device\_train\_batch\_size=8,  
per\_device\_eval\_batch\_size=8,  
evaluation\_strategy=“epoch”,  
logging\_steps=100,  
save\_steps=500,  
learning\_rate=1e-4,  
)

trainer = Trainer(  
model=model,  
args=training\_args,  
train\_dataset=train\_dataset,  
eval\_dataset=test\_dataset,  
)

trainer.train()

trainer.save\_model(“./mymodel”)
