# Neural networks and music

#### Avatrin

Hi

What approach should I take if I want to try this with music?

I know the mathematics that are needed to learn neural networks (from what I have read on websites like Coursera). Also, I know basic scientific programming with Python.

I am willing to spend time to learn how to make the musical equivalent to the art above. What skills do I need?

I know SuperCollider is a programming language made specifically for music, but is it useful for this? The impression I get is that it will be hard to import music to it to make new music.

Yeah, I know it will probably take more than a year, maybe several years, to learn it all, but I am willing to spend the time to do it.

Related Programming and Computer Science News on Phys.org

#### jedishrfu

Mentor
The article you referenced referenced an arxiv article more details about what was done using convolution neural nets for image analysis. Perhaps in researching you will gain on how write a musical version.

However for music, I'd consider using genetic algorithms instead of neural nets. You could encode a song into a vector of sound elements. Each element would be the note, its state sharp or flat or natural, its duration and whether its part a slide. There may be other parameter needed for the sound element. You'd also need a set of song vectors to start the process and an effective scoring algorithm to throw bad song vectors old.

#### Hornbein

The article you referenced referenced an arxiv article more details about what was done using convolution neural nets for image analysis. Perhaps in researching you will gain on how write a musical version.

However for music, I'd consider using genetic algorithms instead of neural nets. You could encode a song into a vector of sound elements. Each element would be the note, its state sharp or flat or natural, its duration and whether its part a slide. There may be other parameter needed for the sound element. You'd also need a set of song vectors to start the process and an effective scoring algorithm to throw bad song vectors old.
I don't see how such a scoring algorithm could exist.

#### jedishrfu

Mentor
I don't see how such a scoring algorithm could exist.
You could score based on how harmonious it was like does it have a run of chords, does it violate some key signature with too many misplaced sharps and flats. Do sequential notes jump too many octaves... Of course, you'd need to refine the scoring algorithm some to accomplish this perhaps by using known well liked songs.

#### Hornbein

You could score based on how harmonious it was like does it have a run of chords, does it violate some key signature with too many misplaced sharps and flats. Do sequential notes jump too many octaves... Of course, you'd need to refine the scoring algorithm some to accomplish this perhaps by using known well liked songs.
I have been a musician for over 40 years and can tell you that no one knows the rules for producing appealing music. I doubt that any such exist. I'm not optimistic about the neural network either, but at least you would have a chance in that it is not a certainty that it won't work.

Or I guess you could pay a horde of third world teenagers to rate the songs your algorithm produced.

#### Fooality

I played around with the Google deepmind stuff that produced the pictures here:

The general idea was based on downsampling an input image, and then using a convolution neural net to asses what its higher resolution form would like, repeatedly. Aftet many passes, it started to hallucenate things like dogs the NN had been trained for. There's probably no good reason you couldn't do the same with music, but you need a big training set of songs. After that though, and with right choice of inputs you just feed it a recording of your washing machine, and it starts to hallucenate a symphony...

The right inputs for the neural network are the tough part. Maybe look at mp3 compression for some ideas?

#### jedishrfu

Mentor
I have been a musician for over 40 years and can tell you that no one knows the rules for producing appealing music. I doubt that any such exist. I'm not optimistic about the neural network either, but at least you would have a chance in that it is not a certainty that it won't work.

Or I guess you could pay a horde of third world teenagers to rate the songs your algorithm produced.
Im not trying to denigrate your experience as a musician. I thought the OP wanted to see what it takes to generate music on the computer and I provided an approach to consider. Im sure it wont generate exceptional music but could generate comparable music if you start with a single genre of music like folk or hawaiian slack key and use known tunes as the first seed and some simple mutation operators to swap notes or phrases between songs.

In the least it would some programming and how genetic algorithms work.

Mentor

#### Avatrin

This discussion has become way more focused than I intended. I wrote how much I know, which is not much; A bachelor degree worth of mathematics and some programming with Python.

I dont just want to know the machine learning aspect of this. What technologies should I learn? Should I learn some other programming languages?

#### Fooality

This discussion has become way more focused than I intended. I wrote how much I know, which is not much; A bachelor degree worth of mathematics and some programming with Python.

I dont just want to know the machine learning aspect of this. What technologies should I learn? Should I learn some other programming languages?
The AI stuff is really computer intensive, so it runs on GPUs, which are usually programmed in C. But since no one wants to mess with that, people write engines in C to do the math, and wrap them with something like python controllers, and control them through something like a Jupyter notebook, which is an interactive python interpreter in browser window. So you can do it all in python if the existing gpu math libaries have what you need.
Lasgne is a common python wrapped library forcconvnets
http://blog.christianperone.com/2015/08/convolutional-neural-networks-and-feature-extraction-with-python/
I had the code for making convnet LSD imagery I linked to, it takes several hours to get all the pieces and have it running, but at that point you have all you need installed and working. If I happen across it i will post it here.

#### Hornbein

Coolest thing I have seen in many a moon. I am amazed. You really have something there.

#### Fooality

Isn't that cool? To be clear, I didnt have any part of the project, I just tinkered with the code they released because it amazed me too: By all accounts its exactly the imagery from psychedelic experiences, which tells me AI researchers are getting close to real understanding of the brain.

OP, I remembered the name of it, its here:

Install, ipython, open the notebook, and I believe the instructions for all the depdencies are there. Once you install those you have a python based framework for tinkering with neural nets.

Last edited:

#### Jarvis323

Have you seen this Ted talk?

Super awesome! Robots that can improvise with personality, and can emulate styles of specific artists, in real time (they can jam with you). The creator is Gil Weinberg, who has published many papers you've be interested in reading.

Last edited:

#### Aufbauwerk 2045

I wrote some algorithmic composition code when I was learning AI. It's actually quite simple in some ways.

For example, perhaps you want a function to compose a good melody. There are some well-known rules for making good melodies. You use recursive search with backtracking, beginning with the first note, then continuing with each note as you test the existing sequence of notes against the rules for a good melody. The notes are selected at random from the appropriate set of candidate notes. You can do the same with harmony.

There is actually a famous program called CPU Bach by Sid Meier, who designed the Civilization series of games. There is a patent, now expired, in which he and his colleague explain one technique for creating Bach-like music.

There is also Cope who used a so-called recombinant method. He sliced up and then reassembled pieces of Beethoven to get a piece that sounded like Beethoven.

There is also a transition matrix based approach. Some pioneers in computer music analyzed the melodies of Foster and figured out the probability that a note or sequence of notes would be followed by a particular note. For example, the matrix would calculate that you follow A B by C 25% of the time, by D 12% of the time, and so on, depending on the composer's style. This is a crude approach but it did produce melodies reminiscent of Foster.

On a personal note, I realized that by programming algorithmic music, I came to regard human music as a rather pointless activity, and I lost all enjoyment of music for some time. So I abandoned algorithmic composition, and eventually became enough of a human again to be able to enjoy music. Do I care what music a robot brain generates? Not at all.

What is important for me is the human behind the music. For example, when I listen to an emotional song, it only interests me because of the human who created that song. If I knew the melody was generated by a computer, I would not enjoy it. Knowing that it comes from the creative impulse of another human being is part of the appeal. I would say the same about computer-generated art in general. I understand that significant intellectual effort went into it, but for me it has zero emotional appeal.

If a good melody is just a sequence of tones produced according to some algorithm, then I already have a program that can generate as many good melodies as you could ever listen to. So what? After a while it just becomes, to paraphrase Shakespeare, sound and fury signifying nothing.

Last edited:

#### Aufbauwerk 2045

I have been a musician for over 40 years and can tell you that no one knows the rules for producing appealing music. I doubt that any such exist.
I agree. What I learned when I did some music programming was that there is something that good musicians have, that allows them to compose, arrange, and perform music that is loved by other people. Sometimes it is so subtle, I can't explain it logically. I can't reduce it to some algorithm. The whole is greater than the sum of the parts. It is not just a simple set of rules. I know it when I hear it. It moves you, or it does not move you.

It's also subjective. My taste is not the same as others. It's not like math where everyone can agree that a calculation yields the right answer.

#### Aufbauwerk 2045

Hi

What approach should I take if I want to try this with music?

I know the mathematics that are needed to learn neural networks (from what I have read on websites like Coursera). Also, I know basic scientific programming with Python.

I am willing to spend time to learn how to make the musical equivalent to the art above. What skills do I need?

I know SuperCollider is a programming language made specifically for music, but is it useful for this? The impression I get is that it will be hard to import music to it to make new music.

Yeah, I know it will probably take more than a year, maybe several years, to learn it all, but I am willing to spend the time to do it.
By the way, sorry to mention my personal feelings. I do not mean to be negative. I lost interest in some uses of AI. Also I have mixed feelings about music in general. But this is not relevant to your question.

I can definitely see some value in algorithmic music in certain contexts. For example, some people have created dance music using algorithms. I believe there have even been events where they play algorithmic dance music. If people enjoy this, then more power to them.

Also some video games have algorithmic music. You might look into this and try to find out how the algorithmic music in these games was coded. I would bet it was in C/C++, assuming the game was in C/C++.

My approach was to generate notes, as opposed to sounds, and then encode the notes in MIDI. Then I could play the MIDI file on a synthesizer of my choice. I only used software synths. I wrote some code in C and some in Lisp.

I could also generate a score from the note events. The language I used for this is available at lilypond.org.

One program I found useful was SynthFont because I could load a sound font of my choice into SynthFont and play the music that way.

I never wrote my own synthesizer for public release. However, I did develop a synthesizer for learning purposes, using techniques from Petzold's additive synth, from his book Programming Windows 5th edition. That is a good reference if you want to understand how to generate sound on a computer. He used C.

Petzold recreated some complex instrument sounds from old experiments on additive synthesis. I just made a simple organ synth by combining sine waves. This is the basic principle of the Hammond organs.

You will also learn from Petzold how to format a WAV file. Once you have a WAV file it's easy to convert it to MP3 using VLC for example.

If you want to work at the level of raw sound, as opposed to musical notation, then I suggest looking at CMusic. You could generate a score and even instrument specifications using your AI code. You are not restricted to what you can do with traditional music notation. I think this would be the most flexible approach. You can generate just about any sound you want. It may be helpful to search for CMusic and Max Matthews. I believe you can find open source in Lisp and perhaps C from this project. Or you can study the Matthews book and write your own implementation of his concepts.

As far as neural nets vs another approach, I have never used neural nets. I understand they are useful for pattern recognition. Obviously painting and music are quite different art forms. In addition to looking into neural networks, I would read the CPU Bach patent for another approach, and also some of the writings of Cope. Also to see another approach to algorithmic painting check out http://www.kurzweilcyberart.com/aaron/message.html. The Aaron developer used Lisp.

Another interesting site is http://www.music-cog.ohio-state.edu/Humdrum/representations/kern.html. This describes the **kern language they use to represent music for analysis purposes.

Last edited:

#### newjerseyrunner

I think the hardest part of making a neural network deal with music is that each instrument sounds differently. An A on a guitar is not the same as an A on a horn. In fact, I can make several different A sounds on one guitar. A guitar string doesn't vibrate with one frequency, it has a main overtone and a whole bunch of undertones which are usually multiples of the overtone, but not exactly because of the density, material... That's a major reason why guitar music is written with tabs instead of notes. You'd have to train different nets for different instruments then have a deeper layer combine them.

I'm working on a neural network right now, they're training is difficult unless you can define exactly what you want to reward and suppress.

"Neural networks and music"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving