Hello everyone!
Thanks for your patience as I took a short break from #100daysofnetworks so that I could focus on other things for a bit. I’m going to attempt to pick this up again, on weekends, because it is really win-win:
I get to show you all kinds of cool and useful things you can do with graphs
And I get to have a nice creative outlet, which keeps me happy and healthy
I want to get this series going again, but I’m not ready to jump straight back into the weeds, doing temporal network analysis, analyzing entire arXiv ecosystems, etc. Let’s do something a bit more creative and simple.
This morning, I woke up with a song in my head. This is not uncommon, for me. I woke up with “Somewhere Only We Know” on loop in my head. I don’t know why. Maybe I heard it on a Youtube video recently, or something.
I’ve really liked this song for a while. It has a really timeless feel, and I think it’s going to be important for a long time. I like this song so much, I picked up my guitar and worked on learning it. And then, I thought, “I should show my readers how to create word networks, and I should try creating a chord network.”
I have never created a chord network before, but it is a simplification of a word network. Chords carry information. Chords are almost like words. A ‘C’ chord has a different implementation and sound than a ‘C#m’.
One of my favorite ideas is the idea of Computational Humanities, analyzing text and images programmatically (and more). By now, you should realize that I dabble in this domain quite a bit, as this series has talked about music from the beginning. Music is important to me, as is literature.
So, today, I’m going to do something creative.
Create a word graph using the lyrics of this song.
Create a chord graph using the chords of this song.
I’m not doing this because it is incredibly valuable, because it is going to change the world, because it’s going to make me a million dollars. I’m doing this, because it gives me an opportunity to understand a song that I like a little more, and possibly I’ll get a cool learning tool out of this, for creative exploration while playing guitar.
Get the Code
Today’s code has been written. You can get it here: https://github.com/itsgorain/100daysofnetworks/blob/main/day_30_song_word_network.ipynb
Creating Word Graphs (Lyrics and Chords)
The process of converting any text into a network graph is pretty simple:
Get the text into a variable that you can use
Tokenize the text
Create an edgelist using: current_token > next_token
Create a graph using the edgelist
Do whatever you want with the graph
Just follow along with the code and this will be simple and logical to understand. Get text, split the text up into words, and then find the relationship between words. With practice, this becomes very easy.
Word Graph (Lyrics)
The work is shown in the notebook. I will show the results and talk through them. What does the network look like?
As you can see, it is a bit complicated and not super easy to read, but if you know the song, you should be able to understand the directionality. For instance, if you find the word ‘why’, you can follow the lines:
why→don’t→we→go→somewhere→only→we→know
Read that. What do you notice? See any repetition? The word ‘we’ has a forked path:
we→go
we→know
In this song, these lyrics carry the rules and information. But even in this little pocket universe, we can learn a bit about the English language.
But also notice the shape and structure of the song, and then consider simpler songs that you know. When this graph visualized, I was first impressed by the complexity of this song.
As this is a graph, everything that I have covered in this series can be useful.
Centralities can be useful to show the most important words, in various context.
Communities can be useful to show which words go together
Temporal analysis can be used to show how a song progresses
Shortest paths would be interesting to look through
Simple algorithms can be used to create other interesting lyrical alternatives, given the same rules
Imagination and time are your limitations
I want you to look at this and be creatively inspired. Work problems can also be solved with creativity. Not everything is tabular data, and many problems aren’t approached (or weren’t approached previously) because NLP techniques were not widely known. Hopefully, there is less of that these days, as NLP and network analysis are not that difficult to learn. It’s just practice, practice, practice, like anything else.
And also, if you are learning something, we learn better when we study what interests or is helpful to us. So, throughout this series, I’ve shown how to use Spotify, Wikipedia, arXiv, and more, to help you get the data to become creatively inspired and practice. I’m not giving you stale boring astronomy datasets that I found in random repos from the internet.
The lyric network is really interesting, and I could spend some time with it, exploring other possibilities. Maybe I will do more with this.
Chord Graph (Chords)
How does the chord graph look? Follow along with the code to learn how I built it.
As a guitarist and musician, this is really cool. This shows how the chords of the song relate to each other. Without even knowing anything about this song, this network visualization could be useful in learning new chords, practicing chord progression, and coming up with countless ideas for new songs. Notice a few things:
I used a directed graph, today, to show the directionality of the relationships.
There are nodes that do NOT have edges between them. Not all chords are used together. But this is limited to this one song.
So, this is already a fun thing that I can use today while I’m practicing guitar.
And this is enough to algorithmically create the foundation of songs. You don’t need a fancy AI for that. Songs tend to have a simple enough structure, so that we can relate to them. Lyrics and lead guitar get much more complicated, but chords and bassline hold the foundation of any song. The above visualization is the foundation for this song. The musicians hit other notes in their individual performances, but this is the scaffolding.
Have Some AI Art
I asked ChatGPT (GPT 4.0) to draw a few happy AI learning to play music. Enjoy.
Go Learn Guitar!
Now that you know this, if you play guitar, maybe you’ll be able to use this for your own creative exploration of music. Or maybe you don’t play guitar, and you realize that the chord graph is not all that intimidating. It really is not. You could use the chord graph for practice, this week:
Session 1: practice C and G
Session 2: C, G, Dm, Em
Session 3: C → C/B transition: what is this and what does it sound like?
Session 4: Add on more
Etc. When I first started learning guitar, I was showed the C chord and then left alone. This network visualization is much more than I had on day 1, and would be useful for beginners.
In fact, as another idea, chord networks of songs would be a neat learning tool. I’d love to have a whole card deck of these. It’d be a really neat idea for a computational humanities book, showing the networks of various songs. Ideas are endless.
That’s All for Today
Thanks for reading, today. Today is light reading. I just wanted to be creative and have a bit of fun exploring a song that I like. You can use the notebook and swap in a song that you like and do your own analysis. Have fun with it! It’s always fun, and very good learning and practice, which will help you in your data work.
Thanks for reading! If you would like to learn more about networks and network analysis, please buy a copy of my book!