Downloads · 30 days
7
2% of all-time downloads
Ghanibhuti/Musician-Llama-3.2-1B-Instruct
Musician-Llama-3.2-1B-Instruct is a machine learning model from Ghanibhuti. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Fine-tuned Llama 3.2 1B Instruct for Text-to-MIDI Music Generation
Downloads · 30 days
7
2% of all-time downloads
All-time downloads
310
Public
Parameters
1.2B
5 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors4.9 GB · 100%
From the Hugging Face model README
Fine-tuned Llama 3.2 1B Instruct for Text-to-MIDI Music Generation
A specialized music AI assistant that generates MIDI token sequences from natural language music descriptions.
Musician-Llama is a fine-tuned version of Llama 3.2 1B Instruct optimized for converting text descriptions of music into MIDI token sequences. It understands musical concepts, genres, instruments, and styles, enabling creative music generation from simple descriptions.
Input: Natural language music description
Output: MIDI token sequence (pipe-separated format)
pip install transformers torch miditok
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("Ghanibhuti/Musician-Llama-3.2-1B-Instruct", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("Ghanibhuti/Musician-Llama-3.2-1B-Instruct")
from transformers import pipeline
# Create text generation pipeline
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
device_map="auto",
)
# Your music description
USER_INPUT = "Upbeat electronic dance music with strong bass and drum patterns"
# Create chat messages
messages = [
{"role": "system", "content": "You are a helpful music AI assistant specialized in MIDI token generation."},
{"role": "user", "content": USER_INPUT},
]
# Generate MIDI tokens
outputs = pipe(
messages,
max_new_tokens=4096,
temperature=0.7,
top_p=0.8,
top_k=21,
repetition_penalty=1.2,
do_sample=True,
)
# Extract response
assistant_response = outputs[0]["generated_text"][-1]["content"]
tokens = assistant_response.replace(". ", "|").replace(" ", ",").replace(".", "|")
print("Generated MIDI tokens:")
print(tokens)
from miditok import Octuple, TokenizerConfig
from pathlib import Path
# Initialize MIDI tokenizer
config = TokenizerConfig(
pitch_range=(21, 109),
num_velocities=32,
special_tokens=["PAD", "BOS", "EOS", "MASK"],
use_tempos=True,
use_time_signatures=True,
use_programs=True,
num_tempos=32,
tempo_range=(40, 250),
)
miditokenizer = Octuple(config)
# Parse and decode tokens
token_list = [
[int(x) for x in token_tuple_str.split(",")]
for token_tuple_str in tokens.split("|")
if token_tuple_str.strip()
]
# Convert to MIDI
midi_obj = miditokenizer.decode(token_list)
midi_obj.dump_midi("output.mid")
print("✅ MIDI file saved to output.mid")
See the main.ipynb notebook for a complete implementation including:
| Parameter | Default | Description |
|---|---|---|
max_new_tokens | 4096 | Maximum MIDI tokens to generate |
temperature | 0.7 | Creativity level (0.1-1.0) |
top_p | 0.8 | Diversity sampling |
top_k | 21 | Top-K sampling |
repetition_penalty | 1.2 | Penalize repetition |
The model can generate music in various styles:
MIDI tokens are represented as pipe-separated tuples:
384,0,60,100|386,0,60,0|388,0,62,90|...
Each token contains:
# Make sure you're using the correct repo ID
model = AutoModelForCausalLM.from_pretrained("username/Musician-Llama-3.2-1B-Instruct")
# Use device_map for automatic GPU memory management
model = AutoModelForCausalLM.from_pretrained(
"Ghanibhuti/Musician-Llama-3.2-1B-Instruct",
device_map="auto",
torch_dtype="auto",
)
# Filter out empty tokens before decoding
tokens = [t for t in token_list if t and len(t) == 8]
✅ Strengths:
⚠️ Considerations:
Apache License 2.0
@model{musician_llama_2024,
title={Musician-Llama: Text-to-MIDI Music Generation},
author={Your Name},
year={2024},
url={https://huggingface.co/Ghanibhuti/Musician-Llama-3.2-1B-Instruct}
}
For issues, questions, or suggestions, please visit the model repository.
Made with ❤️ for music generation enthusiasts