From Music to Math: Modeling Song Structure with Graphs and Matrices
Turn songs into graphs and matrices—learn sequence modeling with album case studies (Memphis Kee, Nat & Alex Wolff, Hans Zimmer) and hands-on math.
From Music to Math: Modeling Song Structure with Graphs and Matrices
Struggling to turn a song’s flow into something you can analyze, predict, or compose with? You’re not alone. Students and teachers often choke on the jump from ear-driven intuition to formal models: how do you represent a verse that sometimes repeats, a chorus that occasionally skips, or a composer’s recurring motif across an album? In 2026, with AI tools and symbolic datasets more accessible than ever, we can use graph theory and linear algebra to make song structure explicit, testable, and actionable.
Why this matters now (short answer)
Late 2025 and early 2026 saw a surge in tools that combine audio embeddings, symbolic notation, and graph-based sequence models. Composers like Hans Zimmer (joining HBO’s Harry Potter series) continue to highlight motif-driven scoring, while album releases from artists such as Memphis Kee (Dark Skies) and Nat & Alex Wolff show how modern albums mix moods and repeated motifs across tracks. These creative trends map naturally onto mathematical models: sections as nodes, transitions as edges, and probabilities or weights as matrices.
Core idea: Representing song sections as graphs
At its simplest, take a song and label its sections: Intro, Verse, Chorus, Bridge, Outro. Each section becomes a node in a directed graph. When a section follows another, draw a directed edge. Weights on edges can encode counts (how often V → C happens), probabilities (normalized counts), or similarity measures (harmonic proximity, lyrical sentiment).
Why graphs first?
- Graphs make structure visible: repeat patterns, cycles and rarely-used sections stand out.
- Edges can be weighted with musical features: tempo change, key modulation, harmonic tension.
- Graphs generalize easily to albums: nodes can be sections, songs, or motifs.
Step-by-step: Build a transition graph from a song
Follow this workflow in a notebook or on paper. I design it for students who want to move from listening to modeling.
- Annotate the song: mark timestamps for each section (I, V, C, B, O). If you're analyzing an album, annotate each track and its dominant section or motif.
- Collect transitions: Record each immediate transition. For example, if the song sequence is I → V → C → V → C → B → C → O, your counts include V→C twice, C→V once, etc.
- Form the adjacency matrix A: rows and columns represent sections in a fixed order; entries A_ij are counts of transitions from i to j.
- Normalize to get a transition matrix P: divide each row by its sum so rows sum to 1. Now P is a Markov transition matrix.
- Analyze: compute k-step transitions, stationary distribution, entropy, centrality, and spectral features.
Small worked example (4 sections)
We’ll model four sections: Verse (V), Chorus (C), Bridge (B), Outro (O). From annotations we estimate these transition probabilities (a toy model inspired by common pop and indie structures):
P =
[ [0.10, 0.60, 0.10, 0.20], # V -> V,C,B,O
[0.20, 0.30, 0.10, 0.40], # C -> V,C,B,O
[0.00, 0.80, 0.10, 0.10], # B -> V,C,B,O
[1.00, 0.00, 0.00, 0.00] ] # O -> V (song loops back)
Interpretation: from a Verse there's a 60% chance of going to the Chorus; the Bridge almost always leads back to a Chorus; the Outro loops back to Verse (e.g., medley or album flow).
Compute the stationary distribution (why it's useful)
The stationary distribution π solves π = πP, π_i ≥ 0, ∑π_i = 1. It tells which sections the Markov chain visits most in the long run — conceptually similar to which sections dominate a song or album’s narrative.
Solving for our P gives (approx):
- π_V ≈ 0.329
- π_C ≈ 0.371
- π_B ≈ 0.078
- π_O ≈ 0.222
Takeaway: The Chorus (C) has the highest long-run probability — it’s the structural anchor. Bridge (B) is rare. This quantitative view maps to a composer’s intent: make the chorus the emotional center.
Album-level graphs: Memphis Kee and Nat & Alex Wolff case studies
Recent album releases offer useful data for album-level sequence modeling. Consider two different creative approaches released in January 2026:
Memphis Kee — Dark Skies (10 tracks)
Memphis Kee’s Dark Skies is described as brooding with moments of hope. Treat each track as a node, classify each track by dominant tonal center (key) and mood tag (e.g., somber, hopeful, driving), and draw edges for consecutive tracks. We can weight edges by harmonic similarity (circle-of-fifths distance) or by cross-track motif reuse.
- Edges with strong harmonic continuity (relative keys, shared chord progressions) get higher weight.
- Edges where lyrical themes reappear get a sentiment-weighted boost.
Running a clustering algorithm (spectral clustering on the normalized Laplacian of the transition graph) can reveal album acts: an opening cluster of introspective songs, a mid-album building tension cluster, and a closing cluster with hopeful resolutions. This mirrors the narrative Kee described in interviews: a record about evolution and change.
Nat & Alex Wolff — self-titled (6 songs)
The Wolff brothers’ project was described as eclectic and vulnerable. For a short album, motif-level graphs are powerful: nodes = motifs (a melodic figure, a lyrical hook), edges = transitions when motifs co-occur or when one motif segues into another.
In 2026, analysts commonly use mixed-feature graphs: combine symbolic music features (pitch-class sets, rhythm patterns) with audio embeddings (from a model) to build a multi-layer graph. Then use matrix factorization (SVD and PCA) to extract dominant motif components that explain most of the album’s variance.
From graphs to matrices: advanced linear algebra tools
Once you have your adjacency matrix A or transition matrix P, you can bring in the full toolkit of linear algebra:
- Eigenanalysis: Eigenvectors of P^T reveal steady-state behavior; eigenvectors of the adjacency matrix can indicate central motifs (leading eigenvector = eigenvector centrality).
- Spectral clustering: Use the graph Laplacian L = D - A or normalized Laplacian to find communities across songs or motifs (useful for album act segmentation).
- SVD and PCA: Factor a motif-by-song matrix to discover latent harmonic or rhythmic factors driving the album.
- Markov k-step analysis: P^k gives the probabilities of being in each section after k transitions — useful to estimate how often a motif will return after a given number of bars.
- Entropy and predictability: The Shannon entropy of the row distributions shows which sections are predictable vs. exploratory.
Practical tip: detect leitmotifs quantitatively
- Extract repeated melodic fragments (symbolic or pitch contours).
- Construct motif transition counts across the album.
- Normalize to create P and compute eigenvector centrality on the motif graph (dominant eigenvector of A).
- Rank motifs by centrality — the top motifs are your candidates for leitmotifs.
Hans Zimmer, leitmotifs, and large-scale sequence modeling
When Hans Zimmer signs on to high-profile storytelling projects (like the HBO Harry Potter series announced in late 2025), the reuse and transformation of motifs across episodes becomes a compositional strategy. Here’s how to model it:
- Nodes = motifs or scene-types (e.g., arrival, confrontation, resolution).
- Edges = transitions between motifs/scenes, weighted by harmonic modulation or orchestration similarity.
- Use time-aware matrices: add a temporal decay parameter to edges so older motif occurrences contribute less to current transitions.
For long-form scores, graph neural networks (GNNs) and transformer-based sequence models (leveraging symbolic representations) are increasingly common in 2026. They can learn how motifs are transformed, not just repeated — crucial when a motif shifts mode or instrumentation to signal character development.
Actionable exercises for students
Below are hands-on exercises you can do in a few hours with free tools (music21, Python, numpy, networkx).
- Single-song Markov model
- Annotate sections for one song (pick a Memphis Kee track or a Wolff song).
- Build A and normalize to P.
- Compute π (power method: repeatedly multiply an initial distribution by P until convergence).
- Interpret π — which section dominates?
- Album motif graph
- Extract 3–5 short melodic motifs per track.
- Construct a motif transition matrix and compute eigenvector centrality.
- Visualize the motif graph with node size proportional to centrality.
- Spectral clustering for acts
- Construct a track-by-track similarity matrix (harmonic + lyrical).
- Compute Laplacian and cluster into k=2 or 3 groups to hypothesize album acts.
- Compare clusters to artist interviews (e.g., Kee’s description of album evolution).
Interpretation: what your matrices tell you about composition
Numbers become musical insight when interpreted. A high stationary weight on Chorus suggests a song built on repetition and return; a high entropy row for Verse suggests unpredictable songwriting choices; strong modular structure in the album graph indicates clear acts or moods. For composers, these metrics help articulate design choices and iterate intentionally.
“Graphs give composers a map; linear algebra gives them a compass.” — Practical credo for music analysts in 2026.
Tools and 2026 trends to watch
As of early 2026, here are the practical tools and trends to try:
- music21 (symbolic analysis), librosa (audio features), and open-source embeddings for chord and melody recognition.
- NetworkX for graph construction and visualization; numpy/scipy for matrix algebra; scikit-learn for spectral clustering.
- Graph Neural Networks (PyTorch Geometric) to model motif transformations across contexts.
- Transformer-based symbolic models: use them for motif prediction and to generate plausible transitions consistent with learned album style.
- Hybrid pipelines that combine audio embeddings and symbolic features — increasingly common after dataset expansions in late 2025.
Limitations and pitfalls
Be mindful of these common issues:
- Annotation bias: humans disagree on section boundaries. Use clear rules or multiple annotators.
- Sparse data: small albums may not yield robust transition estimates; use smoothing (add-one/Laplace) or Bayesian priors.
- Overfitting to audio features: avoid treating every small timbral change as a structural node.
- Interpreting correlation as causation: a motif’s centrality doesn’t prove creative intent, but it does offer testable hypotheses.
Example: Quick notebook recipe (pseudo-steps)
- Import annotations and build transition counts: A[i,j]++ for each observed i→j.
- Normalize: P = rowwise_divide(A, A.sum(axis=1)).
- Compute stationary π by iterating: v_{t+1} = v_t * P until ||v_{t+1}-v_t|| < tol.
- Compute eigenvectors: w, v = eig(A) or eig(P.T) for centralities and modes.
- Visualize: networkx.draw with node sizes ∝ π or centrality.
Actionable takeaways
- Annotate first, then model: clean annotations reduce noise in matrices.
- Normalize counts to probabilities to compare songs and albums of different lengths.
- Use eigenanalysis to find central motifs and the structural “gravity” of a song or album.
- Combine symbolic and audio features for richer graphs — a leading practice in 2026 research and composition tools.
- Test hypotheses with simulations: sample sequences from P to hear the implied song structure and iterate.
Final thoughts: Why this helps composers and students
Graphs and matrices translate musical intuition into models you can analyze, visualize, and teach. Whether you’re dissecting Memphis Kee’s brooding arcs, mapping motif flow in Nat & Alex Wolff’s intimate tracks, or studying motif transformations in a Hans Zimmer score, the math gives structure to storytelling. In 2026, with better datasets and modeling tools, these approaches are no longer academic curiosities — they’re practical tools for composition, analysis, and pedagogy.
Try it now
Pick a song, label the sections, build the adjacency matrix, and compute the stationary distribution. You’ll turn a listening exercise into a quantifiable claim, and that makes both learning and composing faster and more deliberate.
Want a worksheet and starter notebook? Sign up on equations.top for a downloadable Jupyter notebook that walks through the full example, with code, visualizations, and album-level templates (Memphis Kee and Nat & Alex Wolff examples included).
References & further reading: Rolling Stone interviews (Memphis Kee, Nat & Alex Wolff, Jan 16, 2026), industry coverage of Hans Zimmer’s scoring news (late 2025). For tools: music21, librosa, NetworkX, PyTorch Geometric.
Call to action
Ready to model your favorite album? Download the free notebook, try the exercises, and share your album graph on our Discord for feedback. Turn what you hear into what you can prove — and write better music or teach more clearly because of it.
Related Reading
- The Creator Synopsis Playbook 2026: AI Orchestration, Micro-Formats, and Distribution Signals
- Breaking: OrionCloud Files for IPO — What This Means for Creator Infrastructure
- Pop-Up to Persistent: Cloud Patterns, On-Demand Printing and Seller Workflows for 2026 Micro-Shops
- Future-Proofing Your Creator Carry Kit (2026): Mobility, Monetization and Resilience for People Between Gigs
- How to Vet Rental Add-Ons: Which Tech Extras Are Worth the Price?
- Save on Travel Connectivity: Is Switching to T‑Mobile Worth It for Road Warriors?
- Pop-Up to Permanent: How Boutiques Can Turn Limited Retail Events into Long-Term Jewelry Sales
- How to Launch a Community Buyout for a Shuttered Game (Lessons from New World)
- Winter Layering for Cold Runs: Borrowing Design from Luxury Dog Puffers
Related Topics
equations
Contributor
Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.
Up Next
More stories handpicked for you