Downloads ยท 30 days
9
23% of all-time downloads
Jageen/music-4func
music-4func is a text generation model from Jageen. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as gemma.
Fine-tuned FunctionGemma-270M for music control function calling using LoRA. Achieves 98.9% training accuracy and 100% test accuracy on 4 music control functions.
Downloads ยท 30 days
9
23% of all-time downloads
All-time downloads
40
Public
Repo size
53.3 MB
Likes
1
Public
Click a slice to open those files.
.json34.5 MB ยท 63%
From the Hugging Face model README
Fine-tuned FunctionGemma-270M for music control function calling using LoRA. Achieves 98.9% training accuracy and 100% test accuracy on 4 music control functions.
| Model | Accuracy | Improvement |
|---|---|---|
| Base FunctionGemma | 75% (6/8 tests) | - |
| Fine-tuned (this model) | 100% (8/8 tests) | +25 percentage points |
This model can call 4 music control functions:
Play a specific song by name or artist
Parameters:
song_name (string, required) - Name of the song to playartist (string, optional) - Artist namealbum (string, optional) - Album nameExample:
Input: "Play Bohemian Rhapsody by Queen"
Output: call:play_song{song_name:<escape>Bohemian Rhapsody<escape>,artist:<escape>Queen<escape>}
Control music playback
Parameters:
action (string, required) - One of: play, pause, skip, next, previous, stop, resumeExample:
Input: "Pause the music"
Output: call:playback_control{action:<escape>pause<escape>}
Search for music by query, artist, album, or genre
Parameters:
query (string, required) - Search querytype (string, optional) - One of: song, artist, album, playlist, genreExample:
Input: "Search for rock songs"
Output: call:search_music{query:<escape>rock songs<escape>}
Create a new playlist with a given name
Parameters:
name (string, required) - Name of the playlistExample:
Input: "Create a playlist called Workout Mix"
Output: call:create_playlist{name:<escape>Workout Mix<escape>}
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"google/functiongemma-270m-it",
torch_dtype=torch.float32, # Use float32 for CPU, float16 for GPU
device_map="cpu", # or "auto" for GPU
trust_remote_code=True
)
# Load tokenizer and fine-tuned adapter
tokenizer = AutoTokenizer.from_pretrained("google/functiongemma-270m-it")
model = PeftModel.from_pretrained(base_model, "Jageen/music-4func")
# Optional: Merge for faster inference
model = model.merge_and_unload()
# Define your functions (same as training)
FUNCTIONS = [
{
"type": "function",
"function": {
"name": "play_song",
"description": "Play a specific song by name or artist",
"parameters": {
"type": "object",
"properties": {
"song_name": {"type": "string", "description": "Name of the song"},
"artist": {"type": "string", "description": "Artist name (optional)"},
"album": {"type": "string", "description": "Album name (optional)"}
},
"required": ["song_name"]
}
}
},
{
"type": "function",
"function": {
"name": "playback_control",
"description": "Control music playback",
"parameters": {
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["play", "pause", "skip", "next", "previous", "stop", "resume"],
"description": "Playback action"
}
},
"required": ["action"]
}
}
},
{
"type": "function",
"function": {
"name": "search_music",
"description": "Search for music",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"},
"type": {
"type": "string",
"enum": ["song", "artist", "album", "playlist", "genre"],
"description": "Type of search"
}
},
"required": ["query"]
}
}
},
{
"type": "function",
"function": {
"name": "create_playlist",
"description": "Create a new playlist",
"parameters": {
"type": "object",
"properties": {
"name": {"type": "string", "description": "Playlist name"}
},
"required": ["name"]
}
}
}
]
# Test the model
def predict(user_input):
messages = [{"role": "user", "content": user_input}]
prompt = tokenizer.apply_chat_template(
messages,
tools=FUNCTIONS,
add_generation_prompt=True,
tokenize=False
)
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=128,
do_sample=False,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(
outputs[0][inputs['input_ids'].shape[1]:],
skip_special_tokens=False
)
return response
# Test examples
print(predict("Play Bohemian Rhapsody"))
print(predict("Pause the music"))
print(predict("Search for rock songs"))
print(predict("Create a playlist called Chill Vibes"))
The model generates function calls in FunctionGemma format:
<start_function_call>call:function_name{param1:<escape>value1<escape>,param2:<escape>value2<escape>}<end_function_call>
LoraConfig(
r=16, # LoRA rank
lora_alpha=32, # LoRA alpha
target_modules=[ # All 7 modules (critical!)
"q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"
],
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM"
)
Training data formatted using FunctionGemma's chat template:
messages = [
{"role": "user", "content": "Play Bohemian Rhapsody"},
{
"role": "assistant",
"tool_calls": [{
"type": "function",
"function": {
"name": "play_song",
"arguments": {"song_name": "Bohemian Rhapsody"} # Dict, not JSON string
}
}]
}
]
Tested on 8 diverse commands:
| Test | Input | Expected Function | Result |
|---|---|---|---|
| 1 | "Play Bohemian Rhapsody" | play_song | โ Pass |
| 2 | "Pause the music" | playback_control | โ Pass |
| 3 | "Search for rock songs" | search_music | โ Pass |
| 4 | "Create a workout playlist" | create_playlist | โ Pass |
| 5 | "Play Stairway to Heaven by Led Zeppelin" | play_song | โ Pass |
| 6 | "Skip this song" | playback_control | โ Pass |
| 7 | "Find some Beatles songs" | search_music | โ Pass |
| 8 | "Make a new playlist called Chill" | create_playlist | โ Pass |
Success Rate: 100% (8/8)
| Input | Base Model (75%) | Fine-tuned (100%) |
|---|---|---|
| "Play Bohemian Rhapsody" | โ Correct | โ Correct |
| "Pause the music" | โ Correct | โ Correct |
| "Search for rock songs" | โ Wrong params | โ Correct |
| "Create a workout playlist" | โ Hallucinated | โ Correct |
| "Play Hotel California by Eagles" | โ Correct | โ Correct |
| "Skip to next track" | โ Correct | โ Correct |
| "Find jazz music" | โ Wrong function | โ Correct |
| "New playlist: Party Mix" | โ Invalid format | โ Correct |
json.dumps()โ ๏ธ Important: Missing any of the 7 LoRA target modules causes silent failure (model generates only pad tokens). Always include all modules shown above.
Use the code example above for any Python application.
// Using HuggingFace Swift SDK
import Transformers
let model = HuggingFaceModel(
modelId: "Jageen/music-4func",
baseModel: "google/functiongemma-270m-it"
)
// Using HuggingFace Android SDK
import co.huggingface.transformers.*
val model = PeftModel.fromPretrained(
baseModel = "google/functiongemma-270m-it",
adapter = "Jageen/music-4func"
)
For testing with GPU acceleration:
# Use torch.float16 and device_map="auto" for GPU
base_model = AutoModelForCausalLM.from_pretrained(
"google/functiongemma-270m-it",
torch_dtype=torch.float16,
device_map="auto"
)
This model is based on FunctionGemma and inherits the Gemma License. The fine-tuning code and training approach are licensed under Apache 2.0.
For questions, issues, or collaboration:
Built with โค๏ธ using FunctionGemma and LoRA fine-tuning