Learning Your Playlist
Learning Your Playlist Inside the Music App Giving Mistakes a Score A Price for Weight Size
Imagine building a music app that guesses how much you will like a song. You give songs ratings from zero to ten. The app gets information about each song, such as its speed, bass strength, and amount of singing. Its job is to use that information to predict your rating for a song you have not heard yet. To learn, the app studies songs you have already rated. These are its training examples. Each example contains the song information and your actual rating. Imagine the app predicts eight for a song you rated six. Its prediction is two points too high. Learning means changing the app so that its future predictions tend to get closer to your ratings. But there is a sneaky problem. Suppose most songs you rated highly happened to have titles beginning with the letter B. The app might start treating that letter as an important clue. That could help it match your old ratings without helping it understand your taste. Matching examples is not always the same thing as learning a useful pattern. When a model learns details of its training examples that do not carry over well to new examples, we call that overfitting. A model is the adjustable system making the predictions. Our goal is not just a model that remembers your old playlist. We want one that handles new songs well. That ability is called generalization. One kind of model is a neural network. Picture several rows of small processing units. Information about a song enters the first row, travels through later rows, and eventually becomes a predicted rating. Each row is called a layer. A deep neural network has multiple layers between its incoming information and its answer. Deep describes those layers, not human-like understanding. A processing unit receives numbers, adjusts their influence, combines them, and passes a result onward. It also uses a rule that can change how it responds to that combined number. Those rules help the network learn relationships that simple addition alone could not capture. For example, strong bass might matter differently in a slow song than in a fast one. The adjustable influence on a connection is called a weight. Imagine one unit receives a bass measurement of two. A weight of three makes that connection contribute six, because two times three is six. A weight of one makes it contribute two. A weight of zero makes that connection contribute nothing, no matter what bass measurement arrives. Weights can also be negative. With the same bass measurement of two, a weight of negative three contributes negative six. That contribution pulls the unit's combined number downward instead of upward. A weight's size means its distance from zero, regardless of direction. Three and negative three have the same size, even though their effects point in opposite directions. In a deep network, one connection does not usually translate directly into one clear preference, such as loving bass. Its effect depends on the other connections and processing rules around it. Many connections work together. Still, adjusting their weights changes the prediction. Training repeatedly makes those adjustments, using the mistakes on the training songs as guidance. To guide those adjustments, we need a number that measures prediction mistakes. That number is called a loss. A smaller loss means better predictions on the examples being measured. There are different ways to calculate it. For our ratings, we will square each prediction error, which means multiplying that error by itself, and then average the results. Suppose two songs have actual ratings of six and seven. The app predicts eight and six. For the first song, prediction minus actual rating is two. For the second, it is negative one. Squaring gives four and one, both positive. Add them to get five, then divide by two songs. The average loss is two point five. Squaring prevents positive and negative errors from canceling each other. It also makes a large error count more strongly than a small one. During training, a method called an optimizer uses information about how weight changes affect the loss. It repeatedly nudges the weights toward values that reduce that score. Think of many small adjustments rather than one perfect guess. If training cares only about mistakes on old songs, the network may build an elaborate collection of unreliable clues. We can change the goal: make good predictions, but also pay a cost for certain weight choices. Adding this extra pressure is called regularization. It does not tell the network which song clues are true. It encourages solutions that are less dependent on costly weights. The extra cost is called a penalty. During training, the optimizer now tries to reduce prediction loss plus a weighted penalty. The penalty is not a punishment for a wrong rating. It measures something about the network's weights. This creates a trade-off: a weight must help predictions enough to justify the extra cost it adds. We control the strength of that trade-off with a number usually called lambda. Lambda multiplies the penalty before we add it to prediction loss. If lambda is zero, this penalty has no effect. A small positive lambda adds gentle pressure. A larger lambda makes weight size more expensive. Lambda is a setting we choose, not a song rating. Before comparing weights, we should make input measurements reasonably comparable. Song speed might be measured in hundreds of beats per minute, while bass strength might run from zero to one. Those different measuring scales can require very different weights. Rescaling the inputs helps prevent the penalty from favoring a clue merely because of the units used to measure it. The two methods we are studying differ in how they calculate the penalty. L1, spoken as L one, adds the distances of weights from zero. L2, spoken as L two, adds their squares. We will examine a tiny group of weights so the arithmetic stays clear. In a real network, the same idea can apply across many layers and thousands or millions of connections.
