Answers.Body: <p>You've hit upon the central conundrum of supervised learning: if you want a machine to learn to do something, you need to know how to explain what that something is.</p>
  
  <p>In the case of music, there are several possible approaches:</p>
  
  <ul>
  <li><p>Make one set of "bad" songs, and one set of "good" songs. Develop a measure of how similar two songs are (maybe euclidian distance between their discrete <a href="https://en.wikipedia.org/wiki/Fourier_transform" rel="nofollow noreferrer">Fourier transforms</a> is a good starting place?). Your cost function is then based minimizing the average distance to "good" songs, and maximizing the average distance to "bad" songs. This may not work well though, because good and bad songs might differ only in the occasional misplaced notes.</p></li>
  <li><p>Move to a reinforcement learning paradigm. Listen to each song proposed by your network. Give is a score based on your subjective enjoyment. Your cost function is based on maximizing this score. This might work well, but again, it might not. Music is tricky.</p></li>
  <li><p>Use unsupervised approaches. Reward your network just for making something that resembles music (perhaps using the Fourier transform approach above), without labelling good and bad. The advantage is that you don't need to decide what is good or bad, and so you can use a lot more music in your dataset. The drawback is music as a whole might be too diverse to learn easily from examples.</p></li>
  <li><p>Treat your music as a sequence of notes, and <a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/" rel="nofollow noreferrer">train a generative model</a> to predict future notes on the basis of past notes. You can then generate new music by starting the model with a set of notes and letting it generate new ones for a long time.</p></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T12:57:23.630Z
Answers.Text: @NeilSlater Indeed! I should have thought of that. I've updated the answer.
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T20:17:05.227Z
Answers.Text: About your last point: If I understand you correctly, an option would be to plug a rnn output into its input again, so that the predicted note of the previous timestep is the new input. But how would I train it then? Would I just let it follow existing music, and the error is the difference between the predicted next note and the actual next note in that piece of music?
Answers.UserDisplayName: Ben
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-17T01:15:59.350Z
Answers.Text: @Ben That's the essential idea. There are specific kinds of neural networks that are intended to train on sequences in this way. The link in my last point is to an easy-to-use package for training LSTMs, which might be helpful if you want to go that route.
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-15T23:22:45.370Z
Answers.LastActivityDate: 2018-09-16T12:57:02.357Z
Answers.LastEditDate: 2018-09-16T12:57:02.357Z
Answers.UserDisplayName: John Doucette
Body: <p>Currently, I am interested in how NNs or any other AI models can be used for composing music. </p>
  
  <p>But there are many other interesting applications too, like language processing.</p>
  
  <p>I am wondering that: NNs generally need a cost function for learning. But for example, for composing music, what would be an appropriate cost function? I mean,  algorithms can't (yet) really 'calculate' how good music is, right?</p>
  
Tags: <neural-networks>
Title: How to find a cost function for human data
UserDisplayName: Ben
ThreadText: # How to find a cost function for human data
  
  (Asked by: username_0 on 2018-09-15)
  
  Currently, I am interested in how NNs or any other AI models can be used for composing music.
  
  But there are many other interesting applications too, like language processing.
  
  I am wondering that: NNs generally need a cost function for learning. But for example, for composing music, what would be an appropriate cost function? I mean, algorithms can't (yet) really 'calculate' how good music is, right?
  
  **Tags:** neural-networks
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-15. Score: 1 | Accepted answer
  
  You've hit upon the central conundrum of supervised learning: if you want a machine to learn to do something, you need to know how to explain what that something is.
  
  In the case of music, there are several possible approaches:
  
  * Make one set of "bad" songs, and one set of "good" songs. Develop a measure of how similar two songs are (maybe euclidian distance between their discrete [Fourier transforms](https://en.wikipedia.org/wiki/Fourier_transform) is a good starting place?). Your cost function is then based minimizing the average distance to "good" songs, and maximizing the average distance to "bad" songs. This may not work well though, because good and bad songs might differ only in the occasional misplaced notes.
  * Move to a reinforcement learning paradigm. Listen to each song proposed by your network. Give is a score based on your subjective enjoyment. Your cost function is based on maximizing this score. This might work well, but again, it might not. Music is tricky.
  * Use unsupervised approaches. Reward your network just for making something that resembles music (perhaps using the Fourier transform approach above), without labelling good and bad. The advantage is that you don't need to decide what is good or bad, and so you can use a lot more music in your dataset. The drawback is music as a whole might be too diverse to learn easily from examples.
  * Treat your music as a sequence of notes, and [train a generative model](http://karpathy.github.io/2015/05/21/rnn-effectiveness/) to predict future notes on the basis of past notes. You can then generate new music by starting the model with a set of notes and letting it generate new ones for a long time.
  
  > **Comments:**
  > **username_1**: @NeilSlater Indeed! I should have thought of that. I've updated the answer.  
  > **username_0**: About your last point: If I understand you correctly, an option would be to plug a rnn output into its input again, so that the predicted note of the previous timestep is the new input. But how would I train it then? Would I just let it follow existing music, and the error is the difference between the predicted next note and the actual next note in that piece of music?  
  > **username_1**: @Ben That's the essential idea. There are specific kinds of neural networks that are intended to train on sequences in this way. The link in my last point is to an easy-to-use package for training LSTMs, which might be helpful if you want to go that route.  
  
  ---
  
  