Automatic Speech Recognition
Transformers
Safetensors
phi4mm
text-generation
nlp
code
audio
speech-summarization
speech-translation
visual-question-answering
phi-4-multimodal
phi
phi-4-mini
custom_code
Eval Results
Instructions to use microsoft/Phi-4-multimodal-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-4-multimodal-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="microsoft/Phi-4-multimodal-instruct", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-multimodal-instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
added technical report
Browse filesFiles changed (3)
- .gitattributes+1
- README.md+31-42
- phi_4_mm.tech_report.02252025.pdfAdded+3
33 unmodified lines34353633 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text33 unmodified lines3435363733 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text*.pdf filter=lfs diff=lfs merge=lfs -text
41 unmodified lines42434445464748495051525354163 unmodified lines21821922022122222322422522622796 unmodified lines3243253263273283293303 unmodified lines33433533633733833940 unmodified lines38038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242341 unmodified lines- Vision: English- Audio: English, Chinese, German, French, Italian, Japanese, Spanish, Portugueseπ‘ [Phi-4-multimodal Portal]() <br>π° [Phi-4-multimodal Microsoft Blog]() <br>π [Phi-4-multimodal Technical Report]() <br>π©βπ³ [Phi-4-multimodal Cookbook]() <br>π₯οΈ [Try It](https://aka.ms/try-phi4mm) <br>**Phi-4**: [[multimodal-instruct](https://huggingface.co/microsoft/Phi-3.5-mini-instruct) | [onnx]()]; [[mini-instruct]]();## Intended Uses163 unmodified linestransformers==4.48.2accelerate==1.3.0soundfile==0.13.1pillow==10.3.0```Phi-4-multimodal-instruct is also available in [Azure AI Studio]()### Tokenizer96 unmodified lines### Loading the model locallyAfter obtaining the Phi-4-Mini-MM-Instruct model checkpoints, users can use this sample code for inference.```pythonimport requests3 unmodified linesfrom PIL import Imageimport soundfile as sffrom transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig# Define model pathmodel_path = "microsoft/Phi-4-multimodal-instruct"40 unmodified lines# Part 2: Audio Processingprint("\n--- AUDIO PROCESSING ---")audio_url = "https://voiceage.com/wbsamples/in_mono/Trailer.wav"speech_prompt = "Transcribe the audio to text, and then translate the audio to French. Use <sep> as a separator between the original transcript and the translation."prompt = f'{user_prompt}<|audio_1|>{speech_prompt}{prompt_suffix}{assistant_prompt}'print(f'>>> Prompt\n{prompt}')# Download audio fileaudio_response = requests.get(audio_url)if audio_response.status_code == 200:# First save audio to a temporary filetemp_audio_path = "temp_audio.wav"with open(temp_audio_path, "wb") as f:f.write(audio_response.content)# Read using soundfileaudio, samplerate = sf.read(temp_audio_path)# Process with the modelinputs = processor(text=prompt, audios=[(audio, samplerate)], return_tensors='pt').to('cuda:0')generate_ids = model.generate(**inputs,max_new_tokens=1000,generation_config=generation_config,)generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]print(f'>>> Response\n{response}')# Clean uptry:os.remove(temp_audio_path)print(f"Temporary file {temp_audio_path} removed successfully")except Exception as e:print(f"Error removing temporary file: {e}")else:print(f"Failed to download audio file: {audio_response.status_code}")```## Responsible AI Considerations41 unmodified lines42434445464748495051525354163 unmodified lines21821922022122222322422522622722822923023196 unmodified lines3283293303313323333343 unmodified lines33833934034134234334434540 unmodified lines38638738838939039139239339439539639739839940040140240340440540640740840941041141241 unmodified lines- Vision: English- Audio: English, Chinese, German, French, Italian, Japanese, Spanish, Portugueseπ‘ [Phi-4-multimodal Portal](https://aka.ms/phi-4-multimodal/azure) <br>π° [Phi-4-multimodal Microsoft Blog](https://aka.ms/phi4techblog-feb2025) <br>π [Phi-4-multimodal Technical Report](https://aka.ms/phi-4-multimodal/techreport) <br>π©βπ³ [Phi-4-multimodal Cookbook](https://github.com/microsoft/PhiCookBook) <br>π₯οΈ [Try It](https://aka.ms/try-phi4mm) <br>**Phi-4**: [[multimodal-instruct](https://huggingface.co/microsoft/Phi-4-multimodal-instruct) | [onnx](https://huggingface.co/microsoft/Phi-4-multimodal-instruct)]; [[mini-instruct]](https://huggingface.co/microsoft/Phi-4-mini-instruct);## Intended Uses163 unmodified linestransformers==4.48.2accelerate==1.3.0soundfile==0.13.1pillow==11.1.0scipy==1.15.2torchvision==0.21.0backoff==2.2.1peft==0.13.2```Phi-4-multimodal-instruct is also available in [Azure AI Studio](https://aka.ms/phi-4-multimodal/azure)### Tokenizer96 unmodified lines### Loading the model locallyAfter obtaining the Phi-4-multimodal-instruct model checkpoints, users can use this sample code for inference.```pythonimport requests3 unmodified linesfrom PIL import Imageimport soundfile as sffrom transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfigfrom urllib.request import urlopen# Define model pathmodel_path = "microsoft/Phi-4-multimodal-instruct"40 unmodified lines# Part 2: Audio Processingprint("\n--- AUDIO PROCESSING ---")audio_url = "https://upload.wikimedia.org/wikipedia/commons/b/b0/Barbara_Sahakian_BBC_Radio4_The_Life_Scientific_29_May_2012_b01j5j24.flac"speech_prompt = "Transcribe the audio to text, and then translate the audio to French. Use <sep> as a separator between the original transcript and the translation."prompt = f'{user_prompt}<|audio_1|>{speech_prompt}{prompt_suffix}{assistant_prompt}'print(f'>>> Prompt\n{prompt}')# Downlowd and open audio fileaudio, samplerate = sf.read(io.BytesIO(urlopen(audio_url).read()))# Process with the modelinputs = processor(text=prompt, audios=[(audio, samplerate)], return_tensors='pt').to('cuda:0')generate_ids = model.generate(**inputs,max_new_tokens=1000,generation_config=generation_config,)generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]print(f'>>> Response\n{response}')```## Responsible AI Considerations
123version https://git-lfs.github.com/spec/v1oid sha256:a5469d9123cbee2b41729db3217cacfeaa96eaf543868caa2eeec7cf2d24547dsize 5295165.gitattributes+1
README.md+31-42
phi_4_mm.tech_report.02252025.pdfAdded+3