license: mit
language:
- en
metrics:
- accuracy
pipeline_tag: text-generation
🎼 ChatMusician: Fostering Intrinsic Musical Abilities Into LLM
🌐 DemoPage | 🤗 Dataset | 🤗 Benchmark | 📖 arXiv | Code
🔔News
- 🔥[2023-12-10]: The release of ChatMusician's demo, code, model, data, and benchmark. 😆
- [2023-11-30]: Checkout another awesome project MMMU that includes multimodal music reasoning.
Introduction
While Large Language Models (LLMs) demonstrate impressive capabilities in text generation, we find that their ability has yet to be generalized to music, humanity’s creative language. We introduce ChatMusician, an open-source LLM that integrates intrinsic musical abilities.
It is based on continual pre-training and finetuning LLaMA2 on a text-compatible music representation, ABC notation, and the music is treated as a second language. ChatMusician can understand and generate music with a pure text tokenizer without any external multi-modal neural structures or tokenizers. Interestingly, endowing musical abilities does not harm language abilities, even achieving a slightly higher MMLU score. Our model is capable of composing well-structured, full-length music, conditioned on texts, chords, melodies, motifs, musical forms, etc, surpassing GPT-4 baseline. On our meticulously curated college-level music understanding benchmark, MusicTheoryBench, ChatMusician surpasses LLaMA2 and GPT-3.5 on zero-shot setting by a noticeable margin. Our work reveals that LLMs can be an excellent compressor for music, but there remains significant territory to be conquered. Code, data, model, and benchmark are open-sourced.
Prompt Format
Our model produces symbolic music(ABC notation) well in the following prompts. Here are some musical tasks.
Function: Text2music
Prompt:
Using ABC notation, recreate the given text as a musical score.
Meter C
Notes The parts are commonly interchanged.
Transcription 1997 by John Chambers
Key D
Note Length 1/8
Rhythm reel
Response:
X:1
L:1/8
M:2/2
K:D
"A7" FE |"D" D2 FA dAFD |"A7" CDEF G2 FE |"D" D2 FA dcdf |"E7" edcB"A7" AGFE | |"D" D2 FA dAFD |
"A7" CDEF G2 FG |"D" AdcB"A7" AGFE |"D" D2 F2 D2 :: de |"D" fefg fedc |"Em" B^ABc B2 cd |
"E7" e^def e=dcB |"A" A2 ce aABc | |"D" dcde fdAF |"G" GFGA BdcB |"D" AdcB"A7" Agec |
"D" d2 f2 d2 :|
Prompt:
Develop a tune influenced by Bach's compositions.
Response:
X:1
X:1
T:Music21 Fragment
T:Music21 Fragment
T:Music21
C:Music21
%%score 1 2 3 4
L:1/8
M:4/4
K:C
V:1 treble nm="Piano" snm="Pno"
%%MIDI program 0
%%MIDI control 7 100
%%MIDI control 10 64
L:1/4
V:2 treble nm="Piano" snm="Pno"
%%MIDI channel 3
%%MIDI program 0
%%MIDI control 7 100
%%MIDI control 10 64
V:3 bass nm="Piano" snm="Pno"
%%MIDI channel 4
%%MIDI program 0
%%MIDI control 7 100
%%MIDI control 10 64
V:4 bass nm="Piano" snm="Pno"
%%MIDI channel 5
%%MIDI program 0
%%MIDI control 7 100
%%MIDI control 10 64
V:1
z3 c | B A G F | E D !fermata!E c | d e d c | !fermata!B2 z c | B A G F | E D !fermata!E c | %7
d e d c | !fermata!B2 z e | f e d c | B A !fermata!B B | c d e d | !fermata!c2 z e | d c B A | %14
G A B c | d e d c | !fermata!B2 z e | d c B A | G A B c | d e d c | !fermata!c2 z B | A G F E | %22
D C !fermata!D c | B c d e | d c B A | !fermata!G2 z c | B A G F | E D !fermata!E c | d e d c | %29
!fermata!B2 z e | d c B A | G A B c | d e d c | !fermata!c2 z e | d c B A | G A B c | d e d c | %36
!fermata!c2 z B | A G F E | D C !fermata!D c | B c d e | d c B A | !fermata!G2 z2 |] %42
V:2
z6 CD | EF ED C2 CD | EF ED !fermata!C2 CD | EF GF ED C2 | !fermata!C6 CD | EF ED C2 CD | %6
EF ED !fermata!C2 CD | EF GF ED C2 | !fermata!C6 CD | EF GA GF ED | C2 DE !fermata!F2 DC | %11
B,C DB, C2 CD | !fermata!E6 CD | EF GA GF ED | C2 DE !fermata!F2 DC | B,C DB, C2 CD | %16
!fermata!E6 CD | EF GA GF ED | C2 DE !fermata!F2 DC | B,C DB, C2 CD | !fermata!E6 B,C | %21
DE ^FE D=C B,A, | G,^F, G,2 !fermata!G,2 =F,2 | G,2 A,B, CD EF | !fermata!G6 B,C | DE ^FE D=C B,A, | %26
G,^F, G,2 !fermata!G,2 =F,2 | G,2 A,B, CD EF | !fermata!G6 B,C | DE ^FE D=C B,A, | %30
G,^F, G,2 !fermata!G,2 =F,2 | G,2 A,B, CD EF | !fermata!G6 B,C | DE ^FE D=C B,A, | %34
G,^F, G,2 !fermata!G,2 =F,2 | G,2 A,B, CD EF | !fermata!G6 z2 |] %37
V:3
z6 G,2 | A,2 G,2 G,2 G,2 | G,2 G,2 !fermata!G,2 G,2 | G,2 A,2 B,2 C2 | !fermata!C6 G,2 | %6
A,2 G,2 G,2 G,2 | G,2 G,2 !fermata!G,2 G,2 | G,2 A,2 B,2 C2 | !fermata!C6 G,2 | G,2 A,2 B,2 C2 | %11
C2 B,2 !fermata!C2 B,2 | C2 D2 E2 D2 | !fermata!C6 G,2 | A,2 G,2 G,2 G,2 | G,2 G,2 !fermata!G,2 G,2 | %16
G,2 A,2 B,2 C2 | !fermata!C6 G,2 | G,2 A,2 B,2 C2 | C2 B,2 !fermata!C2 B,2 | C2 D2 E2 D2 | %21
!fermata!C6 B,2 | A,2 G,2 G,2 G,2 | G,2 G,2 !fermata!G,2 G,2 | G,2 A,2 B,2 C2 | !fermata!C6 B,2 | %26
A,2 G,2 G,2 G,2 | G,2 G,2 !fermata!G,2 G,2 | G,2 A,2 B,2 C2 | !fermata!C6 B,2 | A,2 G,2 G,2 G,2 | %31
G,2 G,2 !fermata!G,2 G,2 | G,2 A,2 B,2 C2 | !fermata!C6 z2 |] %34
V:4
z6"C" C,2 |"Am" A,,2"Em" E,2"C" C,2"C" C,2 |"Am" A,,2"Em" E,2"C" !fermata!C,2"C" C,2 | %3
"G" G,,2"Am" A,,2"G" B,,2"C" C,2 |"C" !fermata!C,6"C" C,2 |"Am" A,,2"Em" E,2"C" C,2"C" C,2 | %6
"Am" A,,2"Em" E,2"C" !fermata!C,2"C" C,2 |"G" G,,2"Am" A,,2"G" B,,2"C" C,2 |"C" !fermata!C,6"C" C,2 | %9
"G" G,,2"Am" A,,2"G" B,,2"C" C,2 |"C" C,2"G" G,,2"C" !fermata!C,2"C" C,2 | %11
"C" C,2"G" G,,2"Am" A,,2"G" B,,2 |"C" !fermata!C,6"C" C,2 |"G" G,,2"Am" A,,2"G" B,,2"C" C,2 | %14
"C" C,2"G" G,,2"C" !fermata!C,2"C" C,2 |"G" G,,2"Am" A,,2"G" B,,2"C" C,2 |"C" !fermata!C,6"C" C,2 | %17
"G" G,,2"Am" A,,2"G" B,,2"C" C,2 |"C" C,2"G" G,,2"C" !fermata!C,2"C" C,2 | %19
"G" G,,2"Am" A,,2"G" B,,2"C" C,2 |"C" !fermata!C,6"E" E,2 |"Am" A,,2"Em" E,2"C" C,2"C" C,2 | %
Function: Melody Harmonization
Prompt:
Construct smooth-flowing chord progressions for the supplied music.
|: BA | G2 g2"^(C)" edeg | B2 BA"^(D7)" BcBA | G2 g2 edeg | dBAG A2 BA |
G2 g2"^(C)" edeg | B2 BA B2 d2 | e2 ef e2 (3def | gedB A2 :: BA | G2 BG dGBe |
dBBA"^(D7)" B3 A | G2 BG dGBe | dBAG A4 | G2 BG dGBe | dBBA B3 d |
e2 ef e2 (3def | gedB A2 :|
Response:
X:1
L:1/8
M:2/2
K:G
|: BA |"G" G2 g2"^(C)" edeg |"G" B2 BA"^(D7)" BcBA |"G" G2 g2"Em" edeg |"Am" A2 AG"D7" AcBA |
"G" G2 g2"^(C)" edeg |"G" B2 BA B2 d2 |"C" e2 ef e2 (3def |"D7" gedB A2 :: BA |"G" G2 BG dGBG |
"G" B2 BA"^(D7)" BcBA |"G" G2 BG"Em" dGBG |"Am" A2 AG"D7" AcBA |"G" G2 BG dGBe | dBBA B2 d2 |
"C" e2 ef e2 (3def |"D7" gedB A2 :|
Prompt:
Develop a series of chord pairings that amplify the harmonious elements in the given music piece.
E |: EAA ABc | Bee e2 d | cBA ABc | BEE E2 D | EAA ABc | Bee e2 d |
cBA ^GAB |1 A2 A A2 E :|2 A2 A GAB || c3 cdc | Bgg g2 ^g | aed cBA |
^GAB E^F^G | A^GA BAB | cde fed | cBA ^GAB |1 A2 A GAB :|2 \n A3 A2 ||
Response:
X:1
L:1/8
M:6/8
K:Amin
E |:"Am" EAA ABc |"E7" Bee e2 d |"Am" cBA ABc |"E7" BGE E2 E |
"Am" EAA ABc |"E7" Bee e2 d |"Am" cBA"E7" ^GAB |1"Am" A2 A A2 E :|2
"Am" A2 A GAB ||"C" c3 cdc |"G" Bgg g2 ^g |"Am" aed cBA |
"E7" ^GAB E^F^G |"Am" A^GA"E7" BAB |"Am" cde"Dm" fed |
"Am" cBA"E7" ^GAB |1"Am" A2 A GAB :|2 "Am" A2 A A2 ||
Function: Chord Conditioned Music Generation
Prompt:
Develop a musical piece using the given chord progression. 'Dm', 'C', 'Dm', 'Dm', 'C', 'Dm', 'C', 'Dm'
Response:
X:1
L:1/8
M:6/8
K:F
z4 z D |"Dm" A2 A"C" G2 F |"Dm" FE D D2 D |
"Dm" A2 A"C" G2 A |"Dm" D3 D2 D |"Dm" A2 A"C" G2 F |
"Dm" FE D D2 D |"Dm" F2 G"C" E2 C |"Dm" D3 D2 D |
"F" F2 F F2 c |"Bb" d2 c"^(Gm)" B2 A |
"Gm" G2 G G2 B |"Am" A2 G"A7" FE D |"Dm" F2 F F2 c |
"Bb" d2 c"^(Gm)" B2 A |"Gm" G2 G"A7" A2 G |
"Dm" FE D D2 z |]
Function: Musical Form Conditioned Music Generation
Prompt:
Develop a composition by incorporating elements from the given melodic structure.
Ternary, Sectional: Verse/Chorus/Bridge
Response:
X:1
L:1/8
M:6/8
K:Gmin
|:"Gm" GAB AG^F | GAB c2 c | d2 d cdB | A2 d cBA |
GAB AG^F | GAB c2 c | d2 d cdB |1 AG^F G2 D :|2
AG^F GAB |: c2 c cBA | c2 c cBA | c2 c cBA |
ABA GAB | c2 c cBA | c2 c cBA | d2 d cdB |1
AG^F GAB :|2 AG^F G2 A |:"Bbm" B3 dcB | f2 e dcB |
c2 f c2 c | cfc cBA | ABB dcB | f2 e dcB |
d2 d edc |1 cBA B2 B :|2 cBA G3 ||
Function: Motif and Form Conditioned Music Generation
Text Input:
Create music by incorporating the assigned motif into the predetermined musical arrangement.
Musical Form Input: Only One Section
ABC Notation Music Input:
X:1
L:1/8
M:9/8
K:Emin
vB2 E E2 F G2 A
Response:
X:1
L:1/8
M:9/8
K:Emin
|:"Em" vB2 E E2 F G2 A |"D" B2 e e2 ^d e3 |
"Bm" B2 E E2 F G2 A |"G" B2 G A2 F"C" G2 E |
"Em" vB2 E E2 F G2 A |"D" B2 e e2 ^d"C" e3 |
"Em" ve2 B"^Av" A2 F"Bm" G2 A |1"G" B2 G"D" A2 F"Em" G2 E :|
2"G" B2 G"D" A2 F"G" G3 |"^(C)" ABc"^(D)" ded"G" dBG |
"^(C)" cde"D" dcB"G" A2 G |"^(C)" E2 E"Am" ABc"D" def |
"Em" g2 G"D" FAF"G" G3 |"^(C)" ABc"^(D)" ded"G" dBG |
"^(C)" cde"D" dcB"G" A2 G |"Em" e2 B"^Av" A2 F"Bm" G2 A |
"G" B2 G"D" A2 F"Em" G2 E |]
Function: Music Understanding
Prompt:
Investigate the aspects of this musical work and convey its structural organization using suitable musical words.
X:1
L:1/8
M:2/2
K:G
G2 dG BGdG | G2 dc BAGB | A2 eA cAeA | A2 ed cAFA |
G2 dG BGdG | G2 dc BAGB | ABcd efge |1 aged cAFA :|2
aged ^cdef |: g3 f g2 ef | gedc BA G2 | eaag agea |
aged ^cdef | g3 f g2 ef |gedc BAGB | ABcd efge |1
aged ^cdef :|2 aged cAFA |:"^variations:" G2 BG dGBA |
G2 dG BAGB | A2 cA eAcA | A2 ed cAFA | G2 BG dGBA |
G2 dc BAGB | ABcd efge |1 aged cAFA :|2 aged ^cdef |:
g2 af g2 ef | gedc BAGB | Aaag ageg | aged ^cdef |
gbaf g2 ef | gedc BAGB | ABcd efge |1
aged ^cdef :|2 aged cAFA ||
Response:
Compound Binary
Prompt:
Analyze the musical work and pinpoint the consistent melodic element in every section.
X:1
L:1/8
M:4/4
K:G
ge | d2 G2 cBAG | d2 G2 cBAG | e2 A2 ABcd | edcB A2 Bc |
d2 cB g2 fe | edcB cBAG | BAGE DEGA | B2 G2 G2 :: ga |
b2 gb a2 fa | g2 eg edcB | e2 A2 ABcd | edcB A2 ga |
b2 gb a2 fa | g2 eg edcB | cBAG DEGA | B2 G2 G2 :|
Response:
X:1
L:1/8
M:4/4
K:G
ge d2 G2 cBAG d2 G2 cBAG
Training Data
ChatMusician is pretrained on the 🤗 MusicPile, which is the first pretraining corpus for developing musical abilities in large language models. Check out the dataset card for more details. And supervised finetuned on 1.1M samples(2:1 ratio between music scores and music knowledge & music summary data) from MusicPile. Check our paper for more details.
Training Procedure
We initialized a fp16-precision ChatMusician-Base from the LLaMA2-7B-Base weights, and applied a continual pre-training plus fine-tuning pipeline. LoRA adapters were integrated into the attention and MLP layers, with additional training on embeddings and all linear layers. The maximum sequence length was 2048. We utilized 16 80GB-A800 GPUs for one epoch pre-training and 8 32GB-V100 GPUs for two epoch fine-tuning. DeepSpeed was employed for memory efficiency, and the AdamW optimizer was used with a 1e-4 learning rate and a 5% warmup cosine scheduler. Gradient clipping was set at 1.0. The LoRA parameters dimension, alpha, and dropout were set to 64, 16, and 0.1, with a batch size of 8.
Evaluation
- Music understanding abilities are evaluated on the MusicTheoryBench.
- General language abilities of ChatMusician are evaluated on the Massive Multitask Language Understanding (MMLU) dataset.
Usage
You can use the models through Huggingface's Transformers library. Check our Github repo for more advanced use: https://github.com/hf-lin/ChatMusician
CLI demo
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
from string import Template
prompt_template = Template("Human: ${inst} </s> Assistant: ")
tokenizer = AutoTokenizer.from_pretrained("m-a-p/ChatMusician-v1-sft-78k", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("m-a-p/ChatMusician-v1-sft-78k", trust_remote_code=True).eval()
model.cuda()
generation_config = GenerationConfig(
temperature=0.2,
top_k=40,
top_p=0.9,
do_sample=True,
num_beams=1,
repetition_penalty=1.1,
min_new_tokens=10,
max_new_tokens=1536
)
instruction = """Using ABC notation, recreate the given text as a musical score.
Meter C
Notes The parts are commonly interchanged.
Transcription 1997 by John Chambers
Key D
Note Length 1/8
Rhythm reel
"""
prompt = prompt_template.safe_substitute({"inst": instruction})
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
response = model.generate(
input_ids=inputs["input_ids"].to(model.device),
attention_mask=inputs['attention_mask'].to(model.device),
eos_token_id=tokenizer.eos_token_id,
generation_config=generation_config,
)
response = tokenizer.decode(response[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(response)
Intended Uses
These models are trained for research purposes. They are designed to solve general math problems. They can be used in educational software, tutoring systems, or any application where a solution to a math problem is needed. The models can generate both a chain of thought (CoT) rationale and a program of thought (PoT) rationale, providing a comprehensive solution to a given math problem.
Limitations
We've tried our best to build math generalist models. However, we acknowledge that the models' performance may vary based on the complexity and specifics of the math problem. Still not all mathematical fields can be covered comprehensively.
Citation
If you find our work helpful, feel free to give us a cite.
@misc{yuan2024chatmusician,
title={ChatMusician: Understanding and Generating Music Intrinsically with LLM},
author={Ruibin Yuan and Hanfeng Lin and Yi Wang and Zeyue Tian and Shangda Wu and Tianhao Shen and Ge Zhang and Yuhang Wu and Cong Liu and Ziya Zhou and Ziyang Ma and Liumeng Xue and Ziyu Wang and Qin Liu and Tianyu Zheng and Yizhi Li and Yinghao Ma and Yiming Liang and Xiaowei Chi and Ruibo Liu and Zili Wang and Pengfei Li and Jingcheng Wu and Chenghua Lin and Qifeng Liu and Tao Jiang and Wenhao Huang and Wenhu Chen and Emmanouil Benetos and Jie Fu and Gus Xia and Roger Dannenberg and Wei Xue and Shiyin Kang and Yike Guo},
year={2024},
eprint={2402.16153},
archivePrefix={arXiv},
primaryClass={cs.SD}
}