Views
No views yet
nectec/Pathumma-whisper-th-large-v3 and optimized using DoRA (Weight-Decomposed Low-Rank Adaptation) to handle highly challenging audio environments.all_linear targeting) instead of standard LoRA to achieve better magnitude and directional updates, pushing the Word Error Rate (WER) down to 35.8% on a highly difficult evaluation set.PyThaiNLP for rigorous text normalization, solving Thai floating vowel issues, and converting Arabic numbers to Thai words to match competition standards.transformers and peft libraries.1import torch
2import librosa
3from transformers import WhisperProcessor, WhisperForConditionalGeneration
4from peft import PeftModel
5
6device = "cuda:0" if torch.cuda.is_available() else "cpu"
7base_model_id = "nectec/Pathumma-whisper-th-large-v3"
8peft_model_id = "pmootr/pathumma-large-v3-dora-robust"
9
10# 1. Load Base Model and Processor
11processor = WhisperProcessor.from_pretrained(base_model_id)
12base_model = WhisperForConditionalGeneration.from_pretrained(base_model_id, device_map=device)
13
14# 2. Attach DoRA Adapter and Merge
15model = PeftModel.from_pretrained(base_model, peft_model_id).merge_and_unload()
16
17# 3. Transcribe Audio
18def transcribe(audio_path):
19 # Note: Ensure the audio is preprocessed (noise reduction) for best results
20 audio_array, sr = librosa.load(audio_path, sr=16000)
21 inputs = processor(audio_array, sampling_rate=sr, return_tensors="pt")
22 forced_decoder_ids = processor.get_decoder_prompt_ids(language="thai", task="transcribe")
23
24 with torch.no_grad():
25 predicted_ids = model.generate(
26 inputs.input_features.to(device, dtype=model.dtype),
27 forced_decoder_ids=forced_decoder_ids,
28 max_new_tokens=255,
29 num_beams=5,
30 repetition_penalty=1.2
31 )
32 text = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
33 return text.strip()
34
35# Example:
36# print(transcribe("sample_audio.wav"))