Views
No views yet
| Name | Pre-train Paradigm | Training Data (hour) | Pre-train Context (second) | Model Size | Transformer Layer-Dimension | Feature Rate | Sample Rate | Release Date |
|---|---|---|---|---|---|---|---|---|
| MERT-v1-330M | MLM | 160K | 5 | 330M | 24-1024 | 75 Hz | 24K Hz | 17/03/2023 |
| MERT-v1-95M | MLM | 20K | 5 | 95M | 12-768 | 75 Hz | 24K Hz | 17/03/2023 |
| MERT-v0-public | MLM | 900 | 5 | 95M | 12-768 | 50 Hz | 16K Hz | 14/03/2023 |
| MERT-v0 | MLM | 1000 | 5 | 95 M | 12-768 | 50 Hz | 16K Hz | 29/12/2022 |
| music2vec-v1 | BYOL | 1000 | 30 | 95 M | 12-768 | 50 Hz | 16K Hz | 30/10/2022 |


1from transformers import Wav2Vec2Processor, Data2VecAudioModel
2import torch
3from torch import nn
4from datasets import load_dataset
5
6# load demo audio and set processor
7dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
8dataset = dataset.sort("id")
9sampling_rate = dataset.features["audio"].sampling_rate
10processor = Wav2Vec2Processor.from_pretrained("facebook/data2vec-audio-base-960h")
11
12# loading our model weights
13model = Data2VecAudioModel.from_pretrained("m-a-p/music2vec-v1")
14
15
16# audio file is decoded on the fly
17inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")
18with torch.no_grad():
19 outputs = model(**inputs, output_hidden_states=True)
20
21# take a look at the output shape, there are 13 layers of representation
22# each layer performs differently in different downstream tasks, you should choose empirically
23all_layer_hidden_states = torch.stack(outputs.hidden_states).squeeze()
24print(all_layer_hidden_states.shape) # [13 layer, 292 timestep, 768 feature_dim]
25
26# for utterance level classification tasks, you can simply reduce the representation in time
27time_reduced_hidden_states = all_layer_hidden_states.mean(-2)
28print(time_reduced_hidden_states.shape) # [13, 768]
29
30# you can even use a learnable weighted average representation
31aggregator = nn.Conv1d(in_channels=13, out_channels=1, kernel_size=1)
32weighted_avg_hidden_states = aggregator(time_reduced_hidden_states).squeeze()
33print(weighted_avg_hidden_states.shape) # [768]1@article{li2022map,
2 title={MAP-Music2Vec: A Simple and Effective Baseline for Self-Supervised Music Audio Representation Learning},
3 author={Li, Yizhi and Yuan, Ruibin and Zhang, Ge and Ma, Yinghao and Lin, Chenghua and Chen, Xingran and Ragni, Anton and Yin, Hanzhi and Hu, Zhijie and He, Haoyu and others},
4 journal={arXiv preprint arXiv:2212.02508},
5 year={2022}
6}
7