Genres in Genres
Style evolution analysis for music collections using MuQ-MuLan embeddings.
Project Overview
Genres in Genres is a music style evolution analysis tool that uses MuQ-MuLan embeddings (512-dim vectors) to analyze how an artistβs sound changes over time. It identifies sub-genres within an artistβs discography, visualizes style trajectories, and provides semantic interpretation of musical clusters.
Features
- Automatic artist library scanning and caching
- Sub-genre identification using K-Means clustering (with Auto-K)
- 2D trajectory visualization (PCA/t-SNE/UMAP)
- Semantic radar charts for album comparison
- Streamgraph for temporal style distribution
Installation
./run_demo.sh
This creates a virtual environment and installs dependencies.
Usage
1. Preprocess Audio (Optional)
If you have your own music files:
source venv/bin/activate
pip install muq
python scripts/preprocess.py --device cuda
python scripts/cache_tags.py --max_tags 2000 --format pickle
3. Run Dashboard
./run_demo.sh
./run_demo.sh --port 8080
Open the URL in browser, go to Library tab, select an artist, click Analyze.
4. Run Tests
source venv/bin/activate
python -m pytest tests/
Architecture
Data Flow
- Audio Input β
data/music/{Artist}/{Year}-{Album}/*.mp3
- Feature Extraction β
scripts/preprocess.py uses MuQ-MuLan to generate 512-dim embeddings
- Cache Storage β
data/cache/music/{Artist}.pkl (pickled ArtistCareer objects)
- Analysis β
StyleAnalyzer performs clustering, dimensionality reduction, metrics calculation
- Visualization β Gradio app renders trajectory plots, streamgraphs, radar charts
Core Data Structures (src/core.py)
Track: Single song with metadata (file_path, title, album, release_date)
StyleEmbedding: 512-dim MuLan vector bound to a Track
ArtistCareer: Collection of tracks and embeddings for an artist, sorted chronologically
Key Modules
src/analysis.py: StyleAnalyzer class - clustering (KMeans with auto-K via silhouette score), dimensionality reduction (PCA/t-SNE/UMAP), career report generation
src/metrics.py: MusicMetrics class - computes style velocity (album-to-album change), novelty (departure from past work), cohesion (intra-album consistency)
src/semantics.py: SemanticMapper - maps audio embeddings to human-readable tags using cached text embeddings
src/library_manager.py: Handles filesystem scanning and pickle-based caching
src/visualization.py: GenreTrajectoryVisualizer and CareerStoryteller for all plots
Gradio App Structure (app.py)
- Simulate tab: Generate mock data for testing
- Library tab: Analyze cached artists with configurable clustering and visualization options
- Insight Report tab: AI-generated narrative about style evolution
- Dynamic cluster explorer with audio playback
Directory Structure
genres-in-genres/
βββ app.py # Gradio application
βββ run_demo.sh # Setup script
βββ scripts/
β βββ preprocess.py # Audio feature extraction
β βββ prepare_artist.py # Library preparation
β βββ cache_tags.py # Tag caching
β βββ verify_semantics.py # Model verification
βββ src/
β βββ core.py # Data structures
β βββ library_manager.py # Cache management
β βββ muq.py # MuQ-MuLan wrapper
β βββ analysis.py # Clustering logic
β βββ semantics.py # Semantic mapper
β βββ metrics.py # Style metrics
β βββ mock_data.py # Test data
β βββ visualization.py # Plotting
βββ data/
βββ music/ # Input audio files
βββ cache/ # Cached embeddings
βββ metadata/ # Music4All tags
Music Directory Structure
data/music/{Artist}/{Year}-{Album}/*.mp3
Example: data/music/Radiohead/1997-OK Computer/01 - Airbag.mp3
The year prefix is parsed to order albums chronologically.
Key Metrics
- Velocity: Cosine distance between consecutive album centroids (measures rate of style change)
- Novelty: Cosine distance from current album to cumulative past centroid (measures departure from established style)
- Cohesion: 1 - mean intra-album variance (measures stylistic consistency within an album)
Requirements
- Python 3.8+
- torch, torchaudio
- muq (MuQ-MuLan)
- gradio
- scikit-learn, umap-learn
- matplotlib, seaborn