CoolFace
Modelpublic

huybunn/whisper-small-vietnamese-lyrics-transcription

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes14downloads
Model Card

Whisper Small Vietnamese Lyrics Transcription

Fine-tuned from openai/whisper-small using 4.583 hours of Vietnamese song lyrics for training and 0.516 hours for testing.

It achieves the following results on the evaluation set:

  • —Loss: 0.514788
  • —Wer: 0.205209

Training & Evaluation Results

EpochTraining LossValidation LossWER
1No log1.6533140.322856
2No log1.0484651.033229
31.3362000.8208430.997306
41.3362000.6462600.620117
51.3362000.5147880.205209
60.2562000.5372180.312977
70.2562000.5431390.249663
80.2562000.5496260.212393
90.0471000.5624170.240233
100.0471000.5902770.226762

How to use

python
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import torch
import torchaudio

# Tải processor và model đã fine-tune từ Hugging Face Hub
model_id = "huybunn/whisper-small-vietnamese-lyrics-transcription"
processor = WhisperProcessor.from_pretrained(model_id)
model = WhisperForConditionalGeneration.from_pretrained(model_id)
model.eval()

# Tải và chuẩn hóa âm thanh (mono, 16kHz)
audio_path = "your_audio_path.wav"
waveform, sr = torchaudio.load(audio_path)
if sr != 16000:
    resampler = torchaudio.transforms.Resample(sr, 16000)
    waveform = resampler(waveform)

# Nếu stereo, chọn 1 kênh
if waveform.shape[0] > 1:
    waveform = waveform[0:1, :]

# Các thông số chia đoạn
segment_length_sec = 30  # 30 giây
segment_samples = segment_length_sec * 16000
total_samples = waveform.shape[1]
segments = []

# Chia waveform thành các đoạn 30s
for start in range(0, total_samples, segment_samples):
    end = min(start + segment_samples, total_samples)
    segment = waveform[:, start:end]
    segments.append(segment)

# Nhận diện từng đoạn và ghép lại
final_transcript = ""
for i, segment in enumerate(segments):
    # Nếu đoạn cuối ngắn hơn 30s, không padding cũng được
    inputs = processor(segment.squeeze().numpy(), sampling_rate=16000, return_tensors="pt")
    with torch.no_grad():
        predicted_ids = model.generate(
            inputs["input_features"],
            num_beams=5,
            length_penalty=1.0
        )
    transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
    final_transcript += f"{transcription} "  # hoặc thêm dấu xuống dòng nếu muốn

print(final_transcript.strip())