Views
No views yet
sample_finetune_speech.py script from microsoft/Phi-4-multimodal-instruct| Model | zeroth (CER) | zeroth (WER) | fleurs-ko2en | fleurs-ko2en-cot | fleurs-en2ko | fleurs-en2ko-cot |
|---|---|---|---|---|---|---|
| original | 99.16 | 99.63 | 5.63 | 2.42 | 6.86 | 4.17 |
| Ours - speech full finetune (4 epochs) | 1.61 | 3.54 | 7.67 | 8.38 | 12.31 | 9.69 |
| LoRA finetune (4 epochs) | 2.72 | 7.19 | 7.11 | 9.95 | 13.22 | 10.45 |
| LoRA finetune (1 epoch) | 3.80 | 11.52 | 7.03 | 7.04 | 12.50 | 9.54 |
| Phi-4-mm-inst-zeroth-kor | 7.02 | 17.31 | 7.07 | 9.19 | 13.08 | 9.35 |
flash_attn==2.7.4.post1
torch==2.6.0
transformers==4.48.2
accelerate==1.4.0
soundfile==0.13.1
pillow==11.1.0
scipy==1.15.2
torchvision==0.21.0
backoff==2.2.1
peft==0.14.0
datasets==3.3.2
librosa==0.10.2.post1
pandas==2.2.31from datasets import load_dataset
2from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
3
4max_new_tokens = 256
5ft_model_path = "daekeun-ml/Phi-4-multimodal-finetune-ko-speech"
6generation_config = GenerationConfig.from_pretrained(ft_model_path, 'generation_config.json')
7processor = AutoProcessor.from_pretrained(ft_model_path, trust_remote_code=True)
8model = AutoModelForCausalLM.from_pretrained(
9 ft_model_path,
10 trust_remote_code=True,
11 torch_dtype='auto',
12 _attn_implementation='flash_attention_2',
13).cuda()
14
15user_prompt = '<|user|>'
16assistant_prompt = '<|assistant|>'
17prompt_suffix = '<|end|>'
18
19# task prompt is from technical report
20asr_prompt = f'{user_prompt}<|audio_1|>Transcribe the audio clip into text.{prompt_suffix}{assistant_prompt}'
21ast_ko_prompt = f'{user_prompt}<|audio_1|>Translate the audio to Korean.{prompt_suffix}{assistant_prompt}'
22ast_cot_ko_prompt = f'{user_prompt}<|audio_1|>Transcribe the audio to text, and then translate the audio to Korean. Use <sep> as a separator between the original transcript and the translation.{prompt_suffix}{assistant_prompt}'
23ast_en_prompt = f'{user_prompt}<|audio_1|>Translate the audio to English.{prompt_suffix}{assistant_prompt}'
24ast_cot_en_prompt = f'{user_prompt}<|audio_1|>Transcribe the audio to text, and then translate the audio to English. Use <sep> as a separator between the original transcript and the translation.{prompt_suffix}{assistant_prompt}'
25
26asr_ds = load_dataset("kresnik/zeroth_korean", split="test")
27
28# ASR
29item = asr_ds[0]
30audio = (item["audio"]["array"], item["audio"]["sampling_rate"])
31inputs = processor(text=asr_prompt, audios=[audio], return_tensors='pt').to(model.device)
32generate_ids = model.generate(
33 **inputs,
34 max_new_tokens=max_new_tokens,
35 generation_config=generation_config,
36)
37generate_ids = generate_ids[:, inputs['input_ids'].shape[1] :]
38response = processor.batch_decode(
39 generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
40)[0]
41print(response) # "몬터규는 자녀들이 사랑을 제대로 못 받고 크면 매우 심각한 결과가 초래된다는 결론을 내렸습니다"