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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
inference: true
|
3 |
+
tags:
|
4 |
+
- musicgen
|
5 |
+
license: cc-by-nc-4.0
|
6 |
+
pipeline_tag: text-to-audio
|
7 |
+
widget:
|
8 |
+
- text: "a funky house with 80s hip hop vibes"
|
9 |
+
example_title: "Prompt 1"
|
10 |
+
- text: "a chill song with influences from lofi, chillstep and downtempo"
|
11 |
+
example_title: "Prompt 2"
|
12 |
+
- text: "a catchy beat for a podcast intro"
|
13 |
+
example_title: "Prompt 3"
|
14 |
+
---
|
15 |
+
|
16 |
+
# MusicGen - Stereo - Small - 300M
|
17 |
+
|
18 |
+
We further release a set of stereophonic capable models. Those were fine tuned for 200k updates starting
|
19 |
+
from the mono models. The training data is otherwise identical and capabilities and limitations are shared with the base modes. The stereo models work by getting 2 streams of tokens from the EnCodec model, and interleaving those using
|
20 |
+
the delay pattern.
|
21 |
+
|
22 |
+
MusicGen is a text-to-music model capable of genreating high-quality music samples conditioned on text descriptions or audio prompts.
|
23 |
+
It is a single stage auto-regressive Transformer model trained over a 32kHz EnCodec tokenizer with 4 codebooks sampled at 50 Hz.
|
24 |
+
Unlike existing methods, like MusicLM, MusicGen doesn't require a self-supervised semantic representation, and it generates all 4 codebooks in one pass.
|
25 |
+
By introducing a small delay between the codebooks, we show we can predict them in parallel, thus having only 50 auto-regressive steps per second of audio.
|
26 |
+
|
27 |
+
MusicGen was published in [Simple and Controllable Music Generation](https://arxiv.org/abs/2306.05284) by *Jade Copet, Felix Kreuk, Itai Gat, Tal Remez, David Kant, Gabriel Synnaeve, Yossi Adi, Alexandre Défossez*.
|
28 |
+
|
29 |
+
We provide a simple API and 10 pre-trained models. The pre trained models are:
|
30 |
+
- `facebook/musicgen-small`: 300M model, text to music only - [🤗 Hub](https://huggingface.co/facebook/musicgen-small)
|
31 |
+
- `facebook/musicgen-medium`: 1.5B model, text to music only - [🤗 Hub](https://huggingface.co/facebook/musicgen-medium)
|
32 |
+
- `facebook/musicgen-melody`: 1.5B model, text to music and text+melody to music - [🤗 Hub](https://huggingface.co/facebook/musicgen-melody)
|
33 |
+
- `facebook/musicgen-large`: 3.3B model, text to music only - [🤗 Hub](https://huggingface.co/facebook/musicgen-large)
|
34 |
+
- `facebook/musicgen-melody-large`: 3.3B model, text to music and text+melody to music - [🤗 Hub](https://huggingface.co/facebook/musicgen-melody-large)
|
35 |
+
- `facebook/musicgen-stereo-*`: All the previous models fine-tuned for stereo generation -
|
36 |
+
[small](https://huggingface.co/facebook/musicgen-stereo-small),
|
37 |
+
[medium](https://huggingface.co/facebook/musicgen-stereo-medium),
|
38 |
+
[large](https://huggingface.co/facebook/musicgen-stereo-large),
|
39 |
+
[melody](https://huggingface.co/facebook/musicgen-stereo-melody),
|
40 |
+
[melody large](https://huggingface.co/facebook/musicgen-stereo-melody-large)
|
41 |
+
|
42 |
+
## Example
|
43 |
+
|
44 |
+
Try out MusicGen yourself!
|
45 |
+
|
46 |
+
* Audiocraft Colab:
|
47 |
+
|
48 |
+
<a target="_blank" href="https://colab.research.google.com/drive/1fxGqfg96RBUvGxZ1XXN07s3DthrKUl4-?usp=sharing">
|
49 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
50 |
+
</a>
|
51 |
+
|
52 |
+
* Hugging Face Colab:
|
53 |
+
|
54 |
+
<a target="_blank" href="https://colab.research.google.com/github/sanchit-gandhi/notebooks/blob/main/MusicGen.ipynb">
|
55 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
|
56 |
+
</a>
|
57 |
+
|
58 |
+
* Hugging Face Demo:
|
59 |
+
|
60 |
+
<a target="_blank" href="https://huggingface.co/spaces/facebook/MusicGen">
|
61 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/raw/main/open-in-hf-spaces-sm.svg" alt="Open in HuggingFace"/>
|
62 |
+
</a>
|
63 |
+
|
64 |
+
## 🤗 Transformers Usage
|
65 |
+
|
66 |
+
You can run MusicGen locally with the 🤗 Transformers library from version 4.31.0 onwards.
|
67 |
+
|
68 |
+
1. First install the 🤗 [Transformers library](https://github.com/huggingface/transformers) and scipy:
|
69 |
+
|
70 |
+
```
|
71 |
+
pip install --upgrade pip
|
72 |
+
pip install --upgrade transformers scipy
|
73 |
+
```
|
74 |
+
|
75 |
+
2. Run inference via the `Text-to-Audio` (TTA) pipeline. You can infer the MusicGen model via the TTA pipeline in just a few lines of code!
|
76 |
+
|
77 |
+
```python
|
78 |
+
from transformers import pipeline
|
79 |
+
import scipy
|
80 |
+
|
81 |
+
synthesiser = pipeline("text-to-audio", "facebook/musicgen-small")
|
82 |
+
|
83 |
+
music = synthesiser("lo-fi music with a soothing melody", forward_params={"do_sample": True})
|
84 |
+
|
85 |
+
scipy.io.wavfile.write("musicgen_out.wav", rate=music["sampling_rate"], music=audio["audio"])
|
86 |
+
```
|
87 |
+
|
88 |
+
3. Run inference via the Transformers modelling code. You can use the processor + generate code to convert text into a mono 32 kHz audio waveform for more fine-grained control.
|
89 |
+
|
90 |
+
```python
|
91 |
+
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
92 |
+
|
93 |
+
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
94 |
+
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
95 |
+
|
96 |
+
inputs = processor(
|
97 |
+
text=["80s pop track with bassy drums and synth", "90s rock song with loud guitars and heavy drums"],
|
98 |
+
padding=True,
|
99 |
+
return_tensors="pt",
|
100 |
+
)
|
101 |
+
|
102 |
+
audio_values = model.generate(**inputs, max_new_tokens=256)
|
103 |
+
```
|
104 |
+
|
105 |
+
3. Listen to the audio samples either in an ipynb notebook:
|
106 |
+
|
107 |
+
```python
|
108 |
+
from IPython.display import Audio
|
109 |
+
|
110 |
+
sampling_rate = model.config.audio_encoder.sampling_rate
|
111 |
+
Audio(audio_values[0].numpy(), rate=sampling_rate)
|
112 |
+
```
|
113 |
+
|
114 |
+
Or save them as a `.wav` file using a third-party library, e.g. `scipy`:
|
115 |
+
|
116 |
+
```python
|
117 |
+
import scipy
|
118 |
+
|
119 |
+
sampling_rate = model.config.audio_encoder.sampling_rate
|
120 |
+
scipy.io.wavfile.write("musicgen_out.wav", rate=sampling_rate, data=audio_values[0, 0].numpy())
|
121 |
+
```
|
122 |
+
|
123 |
+
For more details on using the MusicGen model for inference using the 🤗 Transformers library, refer to the [MusicGen docs](https://huggingface.co/docs/transformers/model_doc/musicgen).
|
124 |
+
|
125 |
+
## Audiocraft Usage
|
126 |
+
|
127 |
+
You can also run MusicGen locally through the original [Audiocraft library]((https://github.com/facebookresearch/audiocraft):
|
128 |
+
|
129 |
+
1. First install the [`audiocraft` library](https://github.com/facebookresearch/audiocraft)
|
130 |
+
```
|
131 |
+
pip install git+https://github.com/facebookresearch/audiocraft.git
|
132 |
+
```
|
133 |
+
|
134 |
+
2. Make sure to have [`ffmpeg`](https://ffmpeg.org/download.html) installed:
|
135 |
+
```
|
136 |
+
apt get install ffmpeg
|
137 |
+
```
|
138 |
+
|
139 |
+
3. Run the following Python code:
|
140 |
+
|
141 |
+
```py
|
142 |
+
from audiocraft.models import MusicGen
|
143 |
+
from audiocraft.data.audio import audio_write
|
144 |
+
|
145 |
+
model = MusicGen.get_pretrained("small")
|
146 |
+
model.set_generation_params(duration=8) # generate 8 seconds.
|
147 |
+
|
148 |
+
descriptions = ["happy rock", "energetic EDM"]
|
149 |
+
|
150 |
+
wav = model.generate(descriptions) # generates 2 samples.
|
151 |
+
|
152 |
+
for idx, one_wav in enumerate(wav):
|
153 |
+
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
|
154 |
+
audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness")
|
155 |
+
```
|
156 |
+
|
157 |
+
## Model details
|
158 |
+
|
159 |
+
**Organization developing the model:** The FAIR team of Meta AI.
|
160 |
+
|
161 |
+
**Model date:** MusicGen was trained between April 2023 and May 2023.
|
162 |
+
|
163 |
+
**Model version:** This is the version 1 of the model.
|
164 |
+
|
165 |
+
**Model type:** MusicGen consists of an EnCodec model for audio tokenization, an auto-regressive language model based on the transformer architecture for music modeling. The model comes in different sizes: 300M, 1.5B and 3.3B parameters ; and two variants: a model trained for text-to-music generation task and a model trained for melody-guided music generation.
|
166 |
+
|
167 |
+
**Paper or resources for more information:** More information can be found in the paper [Simple and Controllable Music Generation](https://arxiv.org/abs/2306.05284).
|
168 |
+
|
169 |
+
**Citation details:**
|
170 |
+
```
|
171 |
+
@misc{copet2023simple,
|
172 |
+
title={Simple and Controllable Music Generation},
|
173 |
+
author={Jade Copet and Felix Kreuk and Itai Gat and Tal Remez and David Kant and Gabriel Synnaeve and Yossi Adi and Alexandre Défossez},
|
174 |
+
year={2023},
|
175 |
+
eprint={2306.05284},
|
176 |
+
archivePrefix={arXiv},
|
177 |
+
primaryClass={cs.SD}
|
178 |
+
}
|
179 |
+
```
|
180 |
+
|
181 |
+
**License:** Code is released under MIT, model weights are released under CC-BY-NC 4.0.
|
182 |
+
|
183 |
+
**Where to send questions or comments about the model:** Questions and comments about MusicGen can be sent via the [Github repository](https://github.com/facebookresearch/audiocraft) of the project, or by opening an issue.
|
184 |
+
|
185 |
+
## Intended use
|
186 |
+
**Primary intended use:** The primary use of MusicGen is research on AI-based music generation, including:
|
187 |
+
|
188 |
+
- Research efforts, such as probing and better understanding the limitations of generative models to further improve the state of science
|
189 |
+
- Generation of music guided by text or melody to understand current abilities of generative AI models by machine learning amateurs
|
190 |
+
|
191 |
+
**Primary intended users:** The primary intended users of the model are researchers in audio, machine learning and artificial intelligence, as well as amateur seeking to better understand those models.
|
192 |
+
|
193 |
+
**Out-of-scope use cases:** The model should not be used on downstream applications without further risk evaluation and mitigation. The model should not be used to intentionally create or disseminate music pieces that create hostile or alienating environments for people. This includes generating music that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.
|
194 |
+
|
195 |
+
## Metrics
|
196 |
+
|
197 |
+
**Models performance measures:** We used the following objective measure to evaluate the model on a standard music benchmark:
|
198 |
+
|
199 |
+
- Frechet Audio Distance computed on features extracted from a pre-trained audio classifier (VGGish)
|
200 |
+
- Kullback-Leibler Divergence on label distributions extracted from a pre-trained audio classifier (PaSST)
|
201 |
+
- CLAP Score between audio embedding and text embedding extracted from a pre-trained CLAP model
|
202 |
+
|
203 |
+
Additionally, we run qualitative studies with human participants, evaluating the performance of the model with the following axes:
|
204 |
+
|
205 |
+
- Overall quality of the music samples;
|
206 |
+
- Text relevance to the provided text input;
|
207 |
+
- Adherence to the melody for melody-guided music generation.
|
208 |
+
|
209 |
+
More details on performance measures and human studies can be found in the paper.
|
210 |
+
|
211 |
+
**Decision thresholds:** Not applicable.
|
212 |
+
|
213 |
+
## Evaluation datasets
|
214 |
+
|
215 |
+
The model was evaluated on the [MusicCaps benchmark](https://www.kaggle.com/datasets/googleai/musiccaps) and on an in-domain held-out evaluation set, with no artist overlap with the training set.
|
216 |
+
|
217 |
+
## Training datasets
|
218 |
+
|
219 |
+
The model was trained on licensed data using the following sources: the [Meta Music Initiative Sound Collection](https://www.fb.com/sound), [Shutterstock music collection](https://www.shutterstock.com/music) and the [Pond5 music collection](https://www.pond5.com/). See the paper for more details about the training set and corresponding preprocessing.
|
220 |
+
|
221 |
+
## Evaluation results
|
222 |
+
|
223 |
+
Below are the objective metrics obtained on MusicCaps with the released model. Note that for the publicly released models, we had all the datasets go through a state-of-the-art music source separation method, namely using the open source [Hybrid Transformer for Music Source Separation](https://github.com/facebookresearch/demucs) (HT-Demucs), in order to keep only the instrumental part. This explains the difference in objective metrics with the models used in the paper.
|
224 |
+
|
225 |
+
| Model | Frechet Audio Distance | KLD | Text Consistency | Chroma Cosine Similarity |
|
226 |
+
|---|---|---|---|---|
|
227 |
+
| **facebook/musicgen-small** | 4.88 | 1.42 | 0.27 | - |
|
228 |
+
| facebook/musicgen-medium | 5.14 | 1.38 | 0.28 | - |
|
229 |
+
| facebook/musicgen-large | 5.48 | 1.37 | 0.28 | - |
|
230 |
+
| facebook/musicgen-melody | 4.93 | 1.41 | 0.27 | 0.44 |
|
231 |
+
|
232 |
+
More information can be found in the paper [Simple and Controllable Music Generation](https://arxiv.org/abs/2306.05284), in the Results section.
|
233 |
+
|
234 |
+
## Limitations and biases
|
235 |
+
|
236 |
+
**Data:** The data sources used to train the model are created by music professionals and covered by legal agreements with the right holders. The model is trained on 20K hours of data, we believe that scaling the model on larger datasets can further improve the performance of the model.
|
237 |
+
|
238 |
+
**Mitigations:** Vocals have been removed from the data source using corresponding tags, and then using a state-of-the-art music source separation method, namely using the open source [Hybrid Transformer for Music Source Separation](https://github.com/facebookresearch/demucs) (HT-Demucs).
|
239 |
+
|
240 |
+
**Limitations:**
|
241 |
+
|
242 |
+
- The model is not able to generate realistic vocals.
|
243 |
+
- The model has been trained with English descriptions and will not perform as well in other languages.
|
244 |
+
- The model does not perform equally well for all music styles and cultures.
|
245 |
+
- The model sometimes generates end of songs, collapsing to silence.
|
246 |
+
- It is sometimes difficult to assess what types of text descriptions provide the best generations. Prompt engineering may be required to obtain satisfying results.
|
247 |
+
|
248 |
+
**Biases:** The source of data is potentially lacking diversity and all music cultures are not equally represented in the dataset. The model may not perform equally well on the wide variety of music genres that exists. The generated samples from the model will reflect the biases from the training data. Further work on this model should include methods for balanced and just representations of cultures, for example, by scaling the training data to be both diverse and inclusive.
|
249 |
+
|
250 |
+
**Risks and harms:** Biases and limitations of the model may lead to generation of samples that may be considered as biased, inappropriate or offensive. We believe that providing the code to reproduce the research and train new models will allow to broaden the application to new and more representative data.
|
251 |
+
|
252 |
+
**Use cases:** Users must be aware of the biases, limitations and risks of the model. MusicGen is a model developed for artificial intelligence research on controllable music generation. As such, it should not be used for downstream applications without further investigation and mitigation of risks.
|