Views
No views yet
muq lib, and ensure that your python>=3.8:pip3 install muq1import torch, librosa
2from muq import MuQMuLan
3
4# This will automatically fetch checkpoints from huggingface
5device = 'cuda'
6mulan = MuQMuLan.from_pretrained("OpenMuQ/MuQ-MuLan-large")
7mulan = mulan.to(device).eval()
8
9# Extract music embeddings
10wav, sr = librosa.load("path/to/music_audio.wav", sr = 24000)
11wavs = torch.tensor(wav).unsqueeze(0).to(device)
12with torch.no_grad():
13 audio_embeds = mulan(wavs = wavs)
14
15# Extract text embeddings (texts can be in English or Chinese)
16texts = ["classical genres, hopeful mood, piano.", "一首适合海边风景的小提琴曲,节奏欢快"]
17with torch.no_grad():
18 text_embeds = mulan(texts = texts)
19
20# Calculate dot product similarity
21sim = mulan.calc_similarity(audio_embeds, text_embeds)
22print(sim)1import torch, librosa
2from muq import MuQ
3
4device = 'cuda'
5wav, sr = librosa.load("path/to/music_audio.wav", sr = 24000)
6wavs = torch.tensor(wav).unsqueeze(0).to(device)
7
8# This will automatically fetch the checkpoint from huggingface
9muq = MuQ.from_pretrained("OpenMuQ/MuQ-large-msd-iter")
10muq = muq.to(device).eval()
11
12with torch.no_grad():
13 output = muq(wavs, output_hidden_states=True)
14
15print('Total number of layers: ', len(output.hidden_states))
16print('Feature shape: ', output.last_hidden_state.shape)
17| Model Name | Parameters | Data | HuggingFace🤗 |
|---|---|---|---|
| MuQ | ~300M | MSD dataset | OpenMuQ/MuQ-large-msd-iter |
| MuQ-MuLan | ~700M | music-text pairs | OpenMuQ/MuQ-MuLan-large |
@article{zhu2025muq,
title={MuQ: Self-Supervised Music Representation Learning with Mel Residual Vector Quantization},
author={Haina Zhu and Yizhi Zhou and Hangting Chen and Jianwei Yu and Ziyang Ma and Rongzhi Gu and Yi Luo and Wei Tan and Xie Chen},
journal={arXiv preprint arXiv:2501.01108},
year={2025}
}