Showing posts with label pandora. Show all posts
Showing posts with label pandora. Show all posts

What Does Our Music Say About Us? Python Music Experiment Part 2

Subscribe to BrokenAirplane!

Perhaps you tried my class' experiment with their favorite music, finding out the frequency of a word and seeing if there was any significance in the repetition of that word. We did a another experiment where we analyzed the Billboard Top 100 for 2000-2009.

The words that came up most frequently (with a couple of random outliers) were:
Me
My
Got
We
I’m
Love
Your
Mine
With
Baby
I
You
Like
Do you see a connection? They did. Especially as they are reading Romeo and Juliet in their Humanities class. Love and possessions is what the students felt was being repeated over and over. While the profitability in increasing desire and hype over possessions is obvious, I posed to them, "Why might a lyricist or company hype up songs about love?" One student's response, "Because when you are in love you will do anything for them or buy them anything."

I then posed to them the challenge of writing a song (a good song!) that does not use any of these words. It was like lyrical Taboo. It would be interesting to see what our culture would be like if we didn't use these songs in all of our most played songs.

Subscribe to BrokenAirplane and keep up with all of the latest education and technology resources!

What Does Your Music Say About You? Python Music Experiment Part 1

Subscribe to BrokenAirplane

I love the last project of the year. I have spent an entire year with these students learning about their interests and  helping them become proficient in math, science, and programming. I like to experiement with the last project and try something new that hopefully will go well but at least can be refined for next year. I was pleasantly surprised about how this final project went and so I thought I would share it with you.

I am always on the lookout for inspiration for projects and this one began 3 years ago with a fascinating article about Pandora (sorry I don't have it anymore). I was so interested in the way the system learned what you like and don't based upon more than just genre. In fact it was based upon over 400 different factors according to the Music Genome Project on which Pandora is based. I thought this year I would have the students analyze music based upon one of those factors, lyrics.

I asked the students to find 20 song lyrics and paste them into a Google Doc. What was interesting is how often I was asked if they could use songs with profanity, violence, etc. I simply responded that I wanted them to choose their all time favorite songs or the ones they listened to the most and if they didn't then the project wouldn't work.

Next we generated some Pseudocode. I asked them if you were to sit a small child down and tell him to write down how many times a certain word came up in a song what would you tell them?

This took about ten minutes of silent thinking, erasures, and debates so don't get the impression that they got it the first time (but who does).  Eventually the class came up with this.

1
2
3
4
Go through the song.
Each time you come to a word, check to see if that word has come up before.
If it has not, write the word down and a one next to it.
If it has, add one to the count/tally.

Next, we began to translate that into Python script. It gave me an opportunity to talk about data and dictionaries which is always a plus but when we were done, they had a big smile on their face as they realized how similar their pseudocode was to the actual code. To test the code as they were building it, we used Michael Jackson's Smooth Criminal as almost everyone knows it and in my opinion it has the most epic music video of all time. It also has some funky lyrics and punctuation that allows for refining the translate function.

The quick tutorial I gave them to learn about strings can be found here, but as I said this project will be refined as will the tutorial.

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from string import *
song = '''Insert Lyrics Here'''

cleanString = song.translate(None,',.:;!?') #removes these characters
cleanList = cleanString.split() #splits it into a list
    
songDict = {}
for word in cleanList:
    if word not in songDict:
            songDict[word] = 1 #if not already in the dictionary, add it
        else:
            songDict[word]+=1 #if already in the dictionary, add 1 to it
    
print word, songDict[word] #option 1

for word in songDict: #option 2
    if songDict[word] > 1:
        print songDict[word]

The first option will print out the entire dictionary without any filtering. The second option was devised by the students after seeing how many times a word came up only once and will create a threshold to only print words that show up more than once (or more if they want). I love it when they come up with a solution like that!

After they saw the output, I asked them to reflect upon what significant words came up the most for them. For some it was "I, me, you, my" etc. which they saw as an indicator of songs about love and intimacy. Others were surprised how often a curse, violent, or derogatory word came up. Since their humanities teacher is teaching them how to write Sonnets and going through Romeo and Juliet, we ran those words through the code as well. Not surprisingly, the words were very intimate since they are both romantic literature.

Feel free to use the code to analyze your own songs and if you have any thoughts for next year's version of this I would love to hear about it in the comments. I hope to incorporate more of Pandora into the next iteration as I was informed that the software uses a form of the distance formula to decide which song to play next. Ha! Take that those who think Algebra is irrelevant.

Code formatting was made possible via Hilite.me. There are other great options out there but this was the quickest for me. It also made it easy for you to copy and paste the code for your own use. If you have a recommendation of how to do it better, please let me know.

Subscribe to BrokenAirplane and keep up with all of the latest education and technology resources!

Pandora Provides Free Streaming Music for Your Classroom

If there is one thing that your students love, it is music. It has become such a pervasive part of our society. The technology is wonderful but it has the effect of shutting out the world. This, I believe is why so many schools have made the decision to ban MP3 players from school as they prevent teacher/student and student/student interaction.

I love music and have eclectic tastes. It is rare that I do not enjoy others music .I like to play music in the classroom when students are working. It provides a calming effect during math and helps foster interaction between students. The problem is that so many songs have inappropriate words which prevents me from using other student's playlists. To use my player would require sorting through my own music which would take a bunch of time. Plus, any list of songs gets tiring if you hear it enough.

This is where streaming music comes in. Sites like Pandora provide free music that learns from your tastes. For example say you like Pearl Jam, it will use an algorithm (geek fact: it is based on the Distance Formula) to suggest other bands/songs you might like. Based upon your rating of those songs it will begin to learn your tastes. This is a great service that I highly encourage you to take part in.

So every year at the beginning, I provide a Google Form asking for their favorite song/band to relax to and favorite to get energized to. Then I input those choices into Pandora and voila I have two class playlists. All I ask from the students is that they be polite when a song they do not like comes on because it is a song that someone else likes. 

There are other streaming services but I like how Pandora has a wide variety of songs, the ability to filter out inappropriate language, and provides hours of free music.

I hope you and your students benefit from the psychological benefits as well as the increased feeling of community.