Downloads · 30 days
9
30% of all-time downloads
afsagag/t5-spotify-features-generator
t5-spotify-features-generator is a machine learning model from afsagag. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
A fine-tuned T5-base model that generates Spotify audio features from natural language music descriptions.
Downloads · 30 days
9
30% of all-time downloads
All-time downloads
30
Public
Parameters
223M
892 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors892 MB · 100%
From the Hugging Face model README
A fine-tuned T5-base model that generates Spotify audio features from natural language music descriptions.
This model converts natural language descriptions of music preferences into Spotify audio feature values. For example, "energetic dance music for a party" becomes "danceability": 0.9, "energy": 0.9, "valence": 0.9.
Generate Spotify audio features from music descriptions for:
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
# Load model and tokenizer
model = T5ForConditionalGeneration.from_pretrained("afsagag/t5-spotify-features-generator")
tokenizer = T5Tokenizer.from_pretrained("afsagag/t5-spotify-features-generator")
def generate_spotify_features(prompt, model, tokenizer):
input_text = f"prompt: {prompt}"
input_ids = tokenizer(input_text, return_tensors="pt", max_length=256, truncation=True).input_ids
with torch.no_grad():
outputs = model.generate(
input_ids,
max_length=256,
num_beams=4,
early_stopping=True,
do_sample=False,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id
)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
return result
# Example usage
prompt = "I need energetic dance music for a party"
features = generate_spotify_features(prompt, model, tokenizer)
print(features) # Output: "danceability": 0.9, "energy": 0.9, "valence": 0.9
Custom dataset of 4,206 examples pairing natural language music descriptions with Spotify audio features:
Same distribution as training data: natural language music descriptions paired with Spotify audio features.
The model demonstrates strong semantic understanding of musical concepts:
| Prompt | Generated Features |
|---|---|
| "I need energetic dance music for a party" | "danceability": 0.9, "energy": 0.9, "valence": 0.9 |
| "Play calm acoustic songs for studying" | "acousticness": 0.8, "energy": 0.2, "valence": 0.2 |
| "Upbeat music for working out" | "danceability": 0.7, "energy": 0.8, "valence": 0.7 |
| "Relaxing instrumental background music" | "acousticness": 0.3, "energy": 0.2, "instrumentalness": 0.8, "valence": 0.2 |
| "Happy pop music for driving" | "danceability": 0.8, "energy": 0.8, "valence": 0.8 |
"prompt: {natural_language_description}"The model generates these Spotify audio features:
@misc{t5-spotify-features-generator,
author = {afsagag},
title = {T5 Spotify Features Generator: Fine-tuned T5 for Music Feature Prediction from Natural Language},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/afsagag/t5-spotify-features-generator}}
}
afsagag
Contact through Hugging Face profile: @afsagag