Twi ASR โ€” Qwen2-Audio LoRA Adapter

Finetuned LoRA adapter for Twi (Akan) automatic speech recognition. Base model: Qwen/Qwen2-Audio-7B-Instruct Finetuned by FarmerlineML for darli AI.

Inference

import librosa, torch
from transformers import AutoProcessor, Qwen2AudioForConditionalGeneration
from peft import PeftModel

BASE   = "Qwen/Qwen2-Audio-7B-Instruct"
REPO   = "FarmerlineML/twi-asr-qwen2audio-lora"
SYSTEM = (
    "You are a Twi (Akan) speech recognition system. "
    "Transcribe the audio exactly as spoken in Twi. "
    "Return only the Twi transcript, nothing else."
)

processor = AutoProcessor.from_pretrained(REPO)
model = Qwen2AudioForConditionalGeneration.from_pretrained(
    BASE, torch_dtype=torch.bfloat16, device_map="cuda", attn_implementation="sdpa"
)
model = PeftModel.from_pretrained(model, REPO)
model = model.merge_and_unload()
model.eval()

def transcribe(audio_path: str) -> str:
    audio, _ = librosa.load(audio_path, sr=processor.feature_extractor.sampling_rate)
    conversation = [
        {"role": "system", "content": SYSTEM},
        {"role": "user", "content": [
            {"type": "audio", "audio_url": audio_path},
            {"type": "text",  "text": "Transcribe this Twi audio exactly."},
        ]},
    ]
    text   = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
    inputs = processor(
        text=text, audio=audio,
        sampling_rate=processor.feature_extractor.sampling_rate,
        return_tensors="pt"
    ).to("cuda")
    with torch.no_grad():
        out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
    n = inputs["input_ids"].shape[1]
    return processor.batch_decode(out[:, n:], skip_special_tokens=True)[0].strip()

print(transcribe("twi_audio.wav"))
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for FarmerlineML/twi-asr-qwen2audio-lora

Adapter
(18)
this model