Model Details

This model is finetuned on mutiple datasets related to ABC notation (mostly Irish data)

CLI demo for 4-bit quantize

from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig, BitsAndBytesConfig
import torch
import torchaudio
import re

quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.float16,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4"
)

# Alpaca prompt template
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""


tokenizer = AutoTokenizer.from_pretrained("Seeker38/gemma-2-9b-it-abc-notation")

# model 4-bit quant
model = AutoModelForCausalLM.from_pretrained(
    "Seeker38/gemma-2-9b-it-abc-notation", 
    quantization_config=quantization_config,
    device_map="auto",
    resume_download=True
).eval()


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 = """Create a musical composition using the given motif and adhering to the specified musical form represented by alphabet characters.
X:1
L:1/8
Q:3/8=90
M:6/8
K:A
['e cAA ABc dBB Tf2 e fdd', 'e fga']"""
# input_context = "'A', 'D', 'E7', 'A', 'E/G#', 'A', 'Bm', 'A7/C#', 'D', 'E7', 'A', 'A', 'D', 'A', 'A', 'D', 'A', 'A', 'D', 'A', 'D', 'A/D#', 'E', 'A', 'D', 'A', 'A', 'D', 'A', 'E7'"
input_context = ""

prompt = alpaca_prompt.format(
    instruction,    # instruction
    input_context,  # input
    "",            # output - leave this blank for generation!
)

# Tokenize input
inputs = tokenizer([prompt], return_tensors="pt").to("cuda")

# Generate response with specified parameters
with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=2048,
        temperature=0.2,
        top_p=0.9,
        top_k=40,
        use_cache=True,
        do_sample=True,
        repetition_penalty=1.1,
        pad_token_id=tokenizer.eos_token_id
    )

result = tokenizer.batch_decode(outputs, skip_special_tokens=True)
print("Generated Response:")
print(result[0])

# to render abc notation, you need to install symusic
# pip install symusic
import re
from symusic import Score, Synthesizer

abc_notation = re.search(r'### Response:\s*(.*)', result[0], re.DOTALL).group(1).strip()

s = Score.from_abc(abc_notation)
audio = Synthesizer().render(s, stereo=True)
torchaudio.save('cm_music_piece.wav', torch.FloatTensor(audio), 44100)

from IPython.display import Audio, display

from pydub import AudioSegment
wav_link = "cm_music_piece.wav"
mp3_file = AudioSegment.from_wav(wav_link).export("cm_music_piece.mp3", format="mp3")

display(Audio(wav_link))
display(Audio('cm_music_piece.mp3'))

Example Stable Prompts

Here some prompts that are tested to be stable. The convert code and prompt is from ๐Ÿค— ChatMusician.

Function: Chord Conditioned Music Generation

Develop a musical piece using the given chord progression.
'Dm', 'C', 'Dm', 'Dm', 'C', 'Dm', 'C', 'Dm'

Function: Text2music

Develop a tune influenced by Bach's compositions.
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

Function: Melody Harmonization

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 :|
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 ||

Function: Musical Form Conditioned Music Generation

Develop a composition by incorporating elements from the given melodic structure.

Ternary, Sectional: Verse/Chorus/Bridge

Function: Motif and Form Conditioned Music Generation

Create music by following the alphabetic representation of the assigned musical structure and the given motif.

Musical Form Input: AB

ABC Notation Music Input:
X:1
L:1/8
M:2/4
K:D
['d>ef>d g>ef>c d>ef>d c2 e2 d>ef>d g>ef>d', '(3(Ace) (3(Ace)']
Downloads last month
8
Safetensors
Model size
9B params
Tensor type
F16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for Seeker38/gemma-2-9b-it-abc-notation

Finetunes
1 model