Gemma-3-MM is a open multimodal instruction models that extend the
capabilities of the original Gemma-3 models to include speech processing.
These models leverage the language and vision research used in the
original Gemma-3 models and incorporate additional speech processing
capabilities through a Speech Adapter.
The models can process text, image, and audio inputs, generating text outputs, and come with a 128K token context length (32K for the 1B model).
The model was trained by adding a 596B parameter Speech LoRA adapter to the base Gemma-3-4b-it model.
Due to limited computational resources, the model was only trained for limited datasets and epochs on ASR (Automatic Speech Recognition) and AST (Automatic Speech Translation) tasks with A100 1 GPU.
The training data was limited to English and Korean languages within less than 30 seconds in duration.
Note that this model is just a Proof of Concept (PoC) for experimental purposes and is not intended for production use.
To improve the model's performance and reliability, the following areas need further development:
More computational resources for extended training needed.
For now, the model only works for Vision-Language tasks and Audio-Language tasks (ASR/AST).
Due to the lack of computing resources,
this model primarily recognizes audio files less than 30 seconds in duration.
As a result, there is a limitation where the accuracy may drop significantly for longer audio inputs.
If possible, We will train the model for Speech-Vision Tasks and more Audio-Language tasks.
Usage
Below, there are some code snippets on how to get quickly started with running the model.
First, upgrade your Transformers library. AudioInput for chat_template is supported now.
$ pip install -U transformers
Then, copy the snippet from the section that is relevant for your use case.
Running the model with chat_template
python
1from transformers import AutoProcessor, AutoModel
2import torch
34model_id ="junnei/gemma-3-4b-it-speech"5revision ="main"# or "korean".67model = AutoModel.from_pretrained(8 model_id, device_map="auto", revision = revision, trust_remote_code=True9).eval()1011processor = AutoProcessor.from_pretrained(12 model_id, revision = revision, trust_remote_code=True13)1415messages =[16{17"role":"user",18"content":[19{"type":"audio","audio":"https://huggingface.co/microsoft/Phi-4-multimodal-instruct/resolve/main/examples/what_is_shown_in_this_image.wav"},20{"type":"text","text":"Transcribe this audio clip into text."}21]22}23]2425inputs = processor.apply_chat_template(26 messages, add_generation_prompt=True, tokenize=True,27 return_dict=True, return_tensors="pt"28)2930with torch.inference_mode():31 generate_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)32 generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]33 response = processor.batch_decode(34 generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False35)[0]36print(response)3738# What is shown in this image?
Running the model with raw data
python
1from io import BytesIO
2from urllib.request import urlopen
3import soundfile
4from PIL import Image
567# get Audio data from URL8url ="https://huggingface.co/microsoft/Phi-4-multimodal-instruct/resolve/main/examples/what_is_shown_in_this_image.wav"9audio, sr = soundfile.read(BytesIO(urlopen(url).read()))10audio_token ='<start_of_audio>'111213messages =[14{'role':'user','content': audio_token +'Translate this audio into Korean.'},15]1617prompt = processor.tokenizer.apply_chat_template(18 messages, tokenize=False, add_generation_prompt=True19)202122inputs = processor(text=prompt, audio=[audio], add_special_tokens=False, return_tensors="pt")2324with torch.inference_mode():25 generate_ids = model.generate(**inputs, max_new_tokens=128, do_sample=False)26 generate_ids = generate_ids[:, inputs['input_ids'].shape[1]:]27 response = processor.batch_decode(28 generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False29)[0]30print(response)