Friday, May 08, 2015

Ukulele Chords and Perceptrons

As described in this previous post, the  text below is a draft of one of several "interludes" to be included in a book that I am working on concerned with music and artificial neural networks.

Figure I-10. Four examples of four closed form or moveable shapes that define major chords for the ukulele.  See text for details.

Many Diagrams for One Chord

In music theory a tetrachord is merely a chord comprised of four different pitch-classes.  From other perspectives, however, the notion of a tetrachord becomes more practical, and possibly more complicated.
One such practical perspective is provided by the ukulele, which is a small, four-stringed, guitar-like instrument typically tuned to the notes G4, C4, E4 and A4.  Any chord strummed on the ukulele is a tetrachord because it is produced by vibrating these four strings.
Learning to play the ukulele involves studying the finger positions that define various chords.  These positions are provided in charts or books filled with chord diagrams like the examples provided in Figure I-10.  In a chord diagram, the horizontal lines indicate the positions of the frets on a ukulele’s fret board, and the vertical lines represent the instrument’s four strings.  The black dots in a chord diagram indicate where, on the fret board, a finger should be pressed on the string to produce a pitch that is part of the desired chord.
The interacting physical structures of the ukulele and the human hand place constraints on the note combinations that constitute playable ukulele chords.    It is impossible to play every conceivable tetrachord on the ukulele.  A chord that involves placing the index finger on the first fret of one string, and the little finger on the 12th fret of a different string, is a practical impossibility.  In other words, in a playable ukulele chord one’s fingers are not too far apart.
The notes played on different ukulele strings are not too far apart either.  In terms of tuning, the furthest distance is between the C and the A strings, but this distance is only a major sixth (9 semitones).  The G and the A strings only differ by a major second (2 semitones).
The relative nearness of fingers in a playable chord, and the relative nearness of the tunings of ukulele strings, means that relatively minor changes in finger positions can produce the same chord.  This is because the changes in finger positions invert the chord’s notes.  That is, different fingering positions can produce the same component pitches of a chord, but on different strings.
The upshot of this is that there is a many-to-one relationship between fingering patterns and chords.  More than one chord diagram can represent the same ukulele chord.  For example, one of the modern bibles of ukulele chords (Johnson, 2005) provides three different fingerings for each of the 28 chords that it describes for each musical key, producing a book that consists of 1008 different chord diagrams.

Chord Shapes

How does a budding ukulele player even hope to learn such an incredible diversity of possible chords?  Thankfully there are some fingering patterns that can be moved up and down the fret board.  These are called closed form chords because their shape is defined by placing a finger on each of the ukulele’s four strings.  Four examples of such chords are provided in Figure I-10: these are all closed form chords because each chord diagram contains four fingering dots.
When a closed form chord is moved up or down the fret board, it causes the same type of chord to be played, but in a different key.  All of the closed form chord shapes in Figure I-10, for example, create a major chord no matter where they are formed on the fret board.  If one is formed at one location, it produces the B@ major chord.  The same fingering shifted to a different position produces the C major chord.
Closed form chords are efficient for learning the ukulele because once one learns a fingering pattern (e.g. any of the four patterns in Figure I-10), one has really learned 12 different chords.  All the player has to do is learn the name of the chord produced (e.g. B@ major, C major) at each location that the same fingering pattern is used.
Of course not all ukulele chords are closed form.  Some are special cases of closed form chords where the ukulele’s nut (the top of the fret board where the strings end) takes the place of fingers on some of the strings.  The four chord diagrams in Figure I-11 provide examples of such special cases.  These chords are typically learned first, are learned with different fingerings than the patterns in Figure I-10, and are only later related to the more general notion of closed form chords.  Still other chord forms are standalone patterns that cannot be moved along the fret board.  As a result, even learning one kind of chord, such as a major chord, requires acquiring a number of different chord diagrams.
Nevertheless, focusing on the shapes of the chord diagram – the relative positions of fingers on each string – provides efficiency.  The Hal Leonard Ukulele Chord Finder (Johnson, 2005) provides at total of 36 different chord diagrams for the major chords in each musical key.  However, from a player’s perspective, these 36 diagrams can be condensed into only 13 different chord shapes.

Figure I-11. Four special case major chord shapes.  The top fret of each of these chord diagrams is the first fret of a ukulele; the wide horizontal black line in each diagram is the ukulele’s nut.  Each of these shapes is a special instance of each of the four general chord shapes in Figure I-10.  See text for details.

Towards Reverse Chord Finding

Chord dictionaries are organized alphabetically by the root of the chord, and then by chord type.  If you need to find out how to play a particular chord, then you can quickly look it up by using its name.

Learning to play the ukulele is, thankfully, more than just poring through the pages of chord dictionaries.  A player can explore different fingerings without knowing the name of the chords being played.  On finding one such chord that has a particularly pleasing sound, there may be keen interest in finding out the chord’s name.  However, chord dictionaries are not organized by fingering patterns.  This problem – known as reverse chord lookup – does not have an easy book solution.

The reverse chord lookup problem, though, is very similar to problems of identifying scale roots, of identifying scale modes, and of keyfinding that have appeared earlier in this book.  In those earlier problems, a set of notes was presented to a network, and the network output some judgment about the input – a root note, a scale mode, or both.  Is it possible to create a network that can provide the names of chords when provided their fingering?

One complication that presents itself when considering this possibility is the many-to-one relationship between chord diagrams and chords.  In our previous encounters with scale roots and modes, the relationship between input and output was one-to-one.  Can networks adapt to the complexities of many-to-one relationships?

I decided to explore this particular question before facing the larger reverse chord lookup problem.  I trained a network to decide whether a chord was major or minor when presented the chord’s diagram.  This is an interesting test case because, as we have seen, there are many different chord diagrams that are each associated with a major chord.  Furthermore, there is a great deal of similarity between the shapes of major and minor chord diagrams because one can change a major chord into a minor chord by moving only one finger.  Detecting major chords is a challenging problem.

Major chord detection is also an interesting problem with respect to network interpretation.  As discussed above, ukulele players learn chords by paying attention to the shapes of their chord diagrams.  Such shape information is not likely to be directly available to a network whose only window onto a chord diagram is a set of input units.  If a network can detect major chord patterns, then how does it represent their structure?

The first problem to deal with in developing this network is representing input patterns.  I decided to represent each chord diagram as a set of activities using 20 different input units.  Each of these input units indicates a possible finger position on a chord diagram, as is illustrated in Figure I-12.  The first five input units (labeled G1 to G5) represent five possible finger positions on the G string.  The next five input units represent five possible finger positions on the C string, and so on.

Figure I-12. An array of 20 input units used to represent finger positions in a chord diagram.  See text for details.

Any of the chord diagrams in Figures I-10 or I-11 can be represented with this set of input units.  If a string position is fingered in a chord diagram, its input unit is turned on with a value of 1.  Otherwise, its input unit was turned off with a value of 0.  This means that any chord diagram can be represented as a vector of 20 different bits.  For example, the representation of the A major chord in Figure I-11 is [0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].

To explore major chord detection, I created a training set composed of the 36 different instances of chord diagrams for major chords on the ukulele, as well as the 36 different instances of minor chord diagrams, from the Hal Leonard Ukulele Chord Finder (Johnson, 2005).  Each of these 72 chords was converted into a representation that could be encoded in the fashion required by Figure I-12.  I trained a network with one output unit (a value unit with a Gaussian activation function) to turn on when it was presented a major chord pattern, and to turn off when presented a minor chord pattern.

Of course, another key question to answer concerns the nature of the network required to solve this problem.  Does the many-to-one relationship between inputs and outputs require using hidden units?  It turns out that the answer to this question is no.  A perceptron – a network without any hidden units – quickly learns to identify major chords provided that it modifies the output unit’s µ during training.  For instance, the network described below solved this problem after only 397 epochs of training with a learning rate of 0.1

How does this perceptron detect major chord fingerings?  Figure I-13 provides the connection weights from each of the 20 input units to the output unit of this perceptron.  The connection weights in this figure are arranged to correspond to the arrangement of input units in Figure I-12.  Note that the value of µ for this output unit is equal to 1.92.  In order for this output unit to turn on and identify a major chord pattern, the signal coming from the 20 input units must cancel this value out.  In other words, the net input from a major chord pattern must have a value that is very close to -µ, or around -1.92.

A glance at the connection weights in Figure I-13 does not provide any indication that the network is making explicit patterns of the sort that are evident to a human ukulele player in the chord diagrams of
Figures I-10 or I-11.  However, a closer examination reveals that the network has carefully adapted its connection weights to be sensitive to these patterns.  The network has learned that particular combinations of input unit activities (i.e. particular chord patterns) turn the output unit on.  It assigns connection weights so that the sum of their signals cancels
µ out.  Of particular interest, though, is that the network chooses its weights very carefully so that it is equally adept at dealing with the closed form patterns of Figure I-10 and the much sparser special cases of Figure I-11.

Consider the special cases first, because they place important constraints on the connection weights to be assigned.  The C major chord in Figure I-11 requires that only one finger be placed on the third fret of the A string.  This means that the connection weight from input unit A3 must be approximately equal to -µ, because this unit must be able to turn the output unit on by itself.  The weight from this unit is in fact -1.86.

Figure I-13. The connection weights from the 20 input units to the output unit in the major chord detecting perceptron.

The A major chord in Figure I-11 sends signals from input units G2 and C1, while the F major chord in the same figure sends signals from input units G2 and E1.  Because both sets of signals cancel out µ, and because both sets include a signal from G2, the weight from C1 must be the same as the weight from E1.  Figure I-13 shows that both weights are equal to -3.01.

Not surprisingly, any of the chord diagrams illustrated in the earlier figures will produce net inputs that essentially cancel µ out and turn the output unit on.  Training the network has found a set of weights that provide the right combinations to activate the output unit when a major chord pattern is presented, but fail to activate it when a minor chord pattern is given as input.  The surprise here, perhaps, is the speed with which the learning rule discovered the correct combinations of weights to use.

The fact that a network as simple as a perceptron can solve this problem is also exciting because this in turn suggests that this approach can be extended.  It should be possible to train networks to detect many different types of chords, and hopefully their roots, so that one could perform reverse chord lookup by presenting a chord’s fingering to this network.  Developing such a network is my next step in pursuing links between artificial neural networks and the ukulele!



No comments:

Post a Comment