How to use the finetuned model in whisper library #2489
Replies: 1 comment
-
|
It depends on how the model was fine-tuned and which framework was used for training. 1. Fine-tuned with Hugging Face TransformersThis is the most common scenario. Example: from transformers import WhisperForConditionalGeneration
from transformers import WhisperProcessor
model = WhisperForConditionalGeneration.from_pretrained(
"./my_finetuned_whisper"
)
processor = WhisperProcessor.from_pretrained(
"./my_finetuned_whisper"
)You can use the model directly through the Hugging Face pipeline: from transformers import pipeline
pipe = pipeline(
"automatic-speech-recognition",
model="./my_finetuned_whisper"
)
result = pipe("audio.wav")
print(result["text"])This is usually the easiest and safest approach. 2. Can I load it with OpenAI's Whisper library?Not directly in most cases. The OpenAI Whisper library expects checkpoints in the original Whisper format: import whisper
model = whisper.load_model("large-v3")A Hugging Face fine-tuned model contains: while OpenAI Whisper expects: Therefore: whisper.load_model("./my_finetuned_model")will usually fail unless the weights have been converted. 3. If you trained using LoRA / PEFTFor PEFT models: from peft import PeftModel
from transformers import WhisperForConditionalGeneration
base_model = WhisperForConditionalGeneration.from_pretrained(
"openai/whisper-large-v3"
)
model = PeftModel.from_pretrained(
base_model,
"./lora_checkpoint"
)For inference you can either: Option AKeep the LoRA adapters attached: model.generate(...)Option BMerge them into the base model: merged_model = model.merge_and_unload()
merged_model.save_pretrained(
"./merged_whisper"
)After merging, you can use the resulting Hugging Face model normally. 4. If you want to use OpenAI Whisper APIs (
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How to use the finetuned model in whisper library?
Beta Was this translation helpful? Give feedback.
All reactions