Views
No views yet
1from transformers import AutoModelForCausalLM, AutoProcessor, AutoTokenizer
2
3model_id = "mispeech/midashenglm-7b-1021-bf16"
4model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)1user_prompt = "Caption the audio." # You may try any other prompt
2
3messages = [
4 {
5 "role": "user",
6 "content": [
7 {"type": "text", "text": user_prompt},
8 {
9 "type": "audio",
10 "path": "/path/to/example.wav",
11 # or "url": "https://example.com/example.wav"
12 # or "audio": np.random.randn(16000)
13 },
14 ],
15 },
16]1import torch
2
3with torch.no_grad():
4 model_inputs = processor.apply_chat_template(
5 messages,
6 tokenize=True,
7 add_generation_prompt=True,
8 add_special_tokens=True,
9 return_dict=True,
10 ).to(device=model.device, dtype=model.dtype)
11 generation = model.generate(**model_inputs)
12 output = tokenizer.batch_decode(generation, skip_special_tokens=True) # ["An engine is idling."]1@techreport{midashenglm7b,
2 title = {MiDashengLM: Efficient Audio Understanding with General Audio Captions},
3 author = {{Horizon Team, MiLM Plus}},
4 institution= {Xiaomi Inc.},
5 year = {2025},
6 note = {Contributors: Heinrich Dinkel et al. (listed alphabetically in Appendix B)},
7 url = {https://arxiv.org/abs/2508.03983},
8 eprint = {2508.03983},
9}