Views
No views yet
openai/whisper-small with LoRA adapters for Russian transcription.
FInetuned on Farfield part of SberGolos dataset1from huggingface_hub import hf_hub_download
2import torch
3from transformers import WhisperProcessor, WhisperForConditionalGeneration
4
5repo_id = "UDZH/whisper-small-lora-finetuned-ru"
6
7# Loading processor and base model Whisper
8processor = WhisperProcessor.from_pretrained("openai/whisper-small")
9whisper_model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small").to("cuda")
10
11# Loading LoRA weight
12lora_path = hf_hub_download(repo_id=repo_id, filename="whisper_lora_weights.pth")
13lora_weights = torch.load(lora_path, map_location="cuda")
14
15# Apply LoRA to model
16for name, module in whisper_model.named_modules():
17 if isinstance(module, torch.nn.Linear) and any(k in name for k in ["q_proj", "v_proj", "k_proj", "out_proj", "fc1", "fc2"]):
18 parent = whisper_model.get_submodule(".".join(name.split(".")[:-1]))
19 lora_layer = LoRALayer(module, r=16, alpha=32, dropout=0.4).to("cuda")
20 setattr(parent, name.split(".")[-1], lora_layer)
21
22missing_keys, unexpected_keys = whisper_model.load_state_dict(lora_weights, strict=False)
23
24print("LoRA weight loaded.")