IRIS-Embed-Qwen2.5-Omni-3B
IRIS-Embed is an instruction-aware speech embedding model. This model is based on Qwen2.5-Omni-3B.
Model
| Component | Details |
|---|---|
| Backbone | Qwen/Qwen2.5-Omni-3B (Thinker) |
| Text encoder | sentence-transformers/all-MiniLM-L6-v2 |
| Audio states | 33: pre_encoder and encoder_0 through encoder_31 |
| Audio projection | LayerNorm, then Linear (1280 → 2048) |
| Embedding | 2048 dimensions, from the final LLM layer's last non-padding token |
| Similarity | Cosine similarity between L2-normalized embeddings |
MiniLM predicts softmax weights for combining audio encoder states before projection. The states are not normalized before mixing. MiniLM weights and its tokenizer are included in this repository.
We train LoRA adapters in the LLM, the MiniLM routing head, and the audio projection. The routing head is a LayerNorm followed by a linear layer. The base LLM weights, MiniLM text encoder, and audio encoder are frozen during training.
Usage
Use Python 3.12 and PyTorch 2.11. Install the dependencies:
python -m pip install "transformers==5.8.1" "accelerate>=1.13,<2" \
"torchvision>=0.26,<0.27" "pillow>=10" \
"librosa==0.11.0" "soundfile>=0.13,<0.14"
Load the model with Transformers and encode query and document audio:
import librosa
import torch
import torch.nn.functional as F
from transformers import AutoModelForCausalLM, AutoProcessor
model_id = "lca0503/IRIS-Embed-Qwen2.5-Omni-3B"
revision = "main"
model = AutoModelForCausalLM.from_pretrained(
model_id,
revision=revision,
trust_remote_code=True,
dtype=torch.bfloat16,
device_map="auto",
attn_implementation="sdpa",
).eval()
processor = AutoProcessor.from_pretrained(
model_id,
revision=model.config._commit_hash or revision,
trust_remote_code=True,
)
@torch.inference_mode()
def encode(audio_file, instruction=None):
audio, _ = librosa.load(
audio_file, sr=processor.feature_extractor.sampling_rate, mono=True
)
prefix = (
"Document: "
if instruction is None
else f"Instruction: {instruction}\nQuery: "
)
messages = [{
"role": "user",
"content": [
{"type": "text", "text": prefix},
{"type": "audio", "audio": audio},
],
}]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
processor_kwargs={"audio_weight_text": instruction},
).to(model.device)
outputs = model(
**inputs, output_hidden_states=True, return_dict=True, use_cache=False
)
mask = inputs["attention_mask"]
last = mask.shape[1] - 1 - mask.flip(1).argmax(dim=1)
rows = torch.arange(mask.shape[0], device=mask.device)
embedding = outputs.hidden_states[-1][rows, last].float()
return F.normalize(embedding, dim=-1, eps=1e-8).cpu()
query = encode("query.wav", "Find speech from the same speaker as the query.")
documents = torch.cat([encode("document_1.wav"), encode("document_2.wav")])
scores = query @ documents.T
print(scores)
Prompt and router inputs
| Side | LLM user content | MiniLM input |
|---|---|---|
| Query | Instruction: <instruction>\nQuery: <audio> |
Instruction: <instruction>\nQuery: |
| Document | Document: <audio> |
Document: |
Pass the query instruction as audio_weight_text in processor_kwargs.
The processor adds the MiniLM prompt prefix.
For documents, pass None.
The embedding uses the last token of the assistant prefix added by the chat template.
License
The Qwen-derived model is subject to the upstream Qwen Research License, which restricts use to research and evaluation unless a separate commercial license is obtained. MiniLM is provided under Apache-2.0; see LICENSE-MiniLM. See NOTICE for provenance and modifications. This release does not replace the upstream license terms.