[HN Gopher] My approach to automatic musical composition
       ___________________________________________________________________
        
       My approach to automatic musical composition
        
       Author : hackoo
       Score  : 177 points
       Date   : 2022-02-13 13:33 UTC (9 hours ago)
        
 (HTM) web link (flujoo.github.io)
 (TXT) w3m dump (flujoo.github.io)
        
       | SubiculumCode wrote:
       | I'd like tools that would do these transformations in a piano
       | roll, a la FL Studio
        
       | visarga wrote:
       | <off topic>Just dawned on me, today you can generate Mozart's
       | avatar with a GAN, voice with TTS, replies with GPT-3 and music
       | composition on demand with transformers. Or you could demand its
       | opinion on other music, or have it teach you piano. That would be
       | a nice App idea, a MozartBot. Bonus if it can guide you to
       | appreciate the composer's music.
       | 
       | Would this be an early version of digital upload?
        
       | Aidevah wrote:
       | The author has given a very thorough look at the almost purely
       | algorithmic melodic variations in a classical sonata, although I
       | would think starting with Beethoven (and Chopin) may be a bit
       | ambitious. For music of the classical era, the meaning of the
       | music depends on not just melody and harmony, but also
       | articulation and dynamics. In the Beethoven example, the
       | ascending arpeggio is staccato which contrasts against the
       | descending figure which is slurred. The sforzando in bars 5 and 6
       | creates an intensification in comparison to the first four bars
       | which is all in piano; the harmony is the same as before but
       | moves twice as fast and culminates in a rolled fortissimo chord
       | that dies away to a half close. Without the articulation and
       | dynamics, the meaning of the music is changed and its clarity is
       | weakened considerably, which is why I think separating out the
       | melodic aspect is a risky endeavour.
       | 
       | The music of earlier composers, Bach especially, may be more
       | robust when put under this type of algorithmic manipulation since
       | much less sense is lost in Bach even if you only have the melody.
        
       | bambax wrote:
       | I don't think fully automatic musical composition is possible,
       | any more than fully automatic novel writing. A story has to start
       | somewhere and go to some other place, and a musical piece is a
       | story.
       | 
       | Art needs intent.
       | 
       | Actually, art IS intent. (Contemporary art is pure intent: art
       | without artifacts.)
       | 
       | With music, what works (for me) is a mix of algorithmic
       | generation and then selection / arrangement.
       | 
       | Here's a piece I made following that approach: automatic
       | generation of ideas, then me doing the selection, ordering and
       | interpretation.
       | 
       | https://open.spotify.com/track/5TxVfIf9JUAhCEL3O5cWXT
        
       | seanhunter wrote:
       | Most of this writeup is just a reinvention of Schenkerian
       | analysis, and suffers from the same problem, in that you exercise
       | a lot of editorial judgement in deciding which parts are the
       | core/structural ideas and which parts are embellishment. That
       | undermines the whole idea that this is automatic composition,
       | because you are deciding a heck of a lot upfront.
       | https://en.wikipedia.org/wiki/Schenkerian_analysis
       | 
       | The worked example also doesn't follow the stylistic rules that
       | would make it satisfyingly authentic as a variation in the style
       | of Beethoven. To calibrate: if you were to submit it as an
       | exercise for music A-Level in the UK (age 16 pre-university) I
       | don't think you would get a passing mark unless your teacher was
       | feeling particularly generous.
       | 
       | But on the other hand, Classical style is incredibly refined and
       | specific. They could have had much more success producing
       | something following the example of Messiaen, who wrote a specific
       | set of harmonic and rhythmic rules he was going to use for all
       | his compositions which would be relatively easy to encode in a
       | program. ("The technique of my musical language" is the 2-volume
       | book I'm talking about and it's completely amazing btw. He really
       | was an incredibly extraordinary person).
       | 
       | https://www.scribd.com/document/355450046/Messiaen-Olivier-T...
        
       | qrv3w wrote:
       | This is brilliant- nicely written and a great introduction into a
       | neat approach for generating music. The resulting piece is a very
       | convincing piece of classical music too! The simplicity in
       | developed Python framework for this kind of music generation is
       | inspiring- I like the functional approach with defined core
       | elements.
       | 
       | Reverse engineering music is hard, music has patterns but it also
       | has patterns of breaking patterns. I think the heuristics here
       | for compostable repetitive elements that repeat, reduce, and
       | elaborate is a neat approach-very fractal-like in a way.
       | 
       | I'm looking forward to reading the other articles submitted by
       | you!
        
         | mannykannot wrote:
         | You may also find this interesting, about the composer David
         | Cope, the programs he created, and the way they were received:
         | 
         | https://psmag.com/social-justice/triumph-of-the-cyborg-compo...
        
       | adamnemecek wrote:
       | I'm working on an IDE for music composition. Launching soon
       | https://ngrid.io
        
         | meowtimemania wrote:
         | I looked at the home page and it sounds interesting! In what
         | key ways will your software be different than existing ones?
        
           | adamnemecek wrote:
           | It will actually understand music theory.
        
       | motohagiography wrote:
       | What a beautiful write up and description. In naive pursuit of
       | related ideas with less of a grounding in music theory, I use
       | something called a "fractal sequencer," in my modular rack which
       | is like a normal linear sequencer you would find on a synth, but
       | with mutation, recursion, and iteration. This idea of
       | subperficial and deep structure the author talks about, and a
       | fractal tree with trunks and branches, are closely related, and
       | it maps very well to this description. I wanted to see if I could
       | use fractals to generate consonant melodies that were
       | indistinguishable from pop music using patterns called 1/f noise.
       | The idea was I wanted to see whether by just adding musical
       | entropy in the form of 1/f noise to a repetitive pattern if it
       | would be interpreted as persuasively "new" and "interesting," to
       | our brains. My own result is just a rough live take from messing
       | around with it ( https://soundcloud.com/n-gram-music/beatrice )
       | but if you want to know what a consonant autogenerated pop
       | fractal sounds like, the upper solo line over top of the three
       | note melody is produced by on a Qu-Bit Bloom sequencer iterating
       | over a bunch of 4ths and 5ths and driving its own oscillator.
       | Similarily, I recorded one with with a more early 80s electronica
       | tone that is less fun, but more atmosphereic in iterating through
       | the space of possible melodies (https://soundcloud.com/n-gram-
       | music/decade)
       | 
       | This ch0pi1n python library looks supremely interesting, as when
       | we listen to music, we're really expressing structures and shapes
       | in consonance and dissonance with each other where each
       | elaborates facets of the others. These are if not functions, at
       | least algorithms composed over types. The author's description of
       | these is just the right level for deriving and applying a logical
       | architecture without diving into some bonkers numerological
       | gematria. The post is a beautiful way of thinking about these
       | forms. I look forward to revisiting it and playing with the
       | library.
        
       | coldcode wrote:
       | The analysis was interesting but the end result was pretty
       | terrible. Of course music in the past was often considered
       | terrible by the following generation, a trend that still exists
       | today.
       | 
       | What I would really like to see is an attempt to write multipart
       | contrapuntal works like Bach with some kind of AI. The rules are
       | fairly well understood, but Bach knew how to adapt and even
       | violate them all but still wind up with amazing pleasant music.
        
         | ekianjo wrote:
         | sid meier had a software like that he created for the 3do
        
         | hackoo wrote:
         | Is "the end result" the Beethoven's sonata in Japanese scale?
         | 
         | If so, the most important reason that it sounds terrible is the
         | music is generated with MuseScore, without adjusting dynamics,
         | tempos, etc. Actually, the Beethoven's original sonata in this
         | blog is also generated with MuseScore, and it sounds not so
         | good even with dynamics added.
         | 
         | However, this is why I agree that deep leaning is more
         | promising than this manual approach, since too many variables
         | you need to adjust to make music sound good rather than
         | syntactically correct.
        
         | rsfern wrote:
         | Meh. There's plenty of deep learning music generation stuff out
         | there, this is still a really cool approach
         | 
         | I think it would be cool to combine the two. Instead of
         | generating raw midi, your GAN or reinforcement learning agent
         | or whatever could try to generate sequences of transformations
         | to melodic fragments. Neural program synthesis type stuff.
         | 
         | Or maybe one could build an automatic music analysis tool that
         | can start from the score and try to infer the program that
         | generated them. (Is that a thing already?)
        
         | Rochus wrote:
         | See e.g. https://github.com/feynmanliang/bachbot. The companion
         | site is no longer available, but here are some results on
         | soundcloud: https://soundcloud.com/bachbot
         | 
         | Here is another very good one: https://openai.com/blog/musenet/
         | 
         | I'm a trained musician myself and interested in automatic music
         | composition following the progress for the last thirty years,
         | but only recent work (like the ones referenced) produce
         | convincing results (besides Cope's work of course, but which
         | required manual selection and editing).
         | 
         | You might also be interested in this survey paper:
         | https://arxiv.org/abs/1709.01620
        
         | zozbot234 wrote:
         | This comment should not be disregarded so easily. The reason
         | why deep sequence learning has the best results in generating
         | complex, highly contrapuntal music (it's more like noodling or
         | improvisation than an actual compositional process, but it _is_
         | generally compelling at its best) is precisely because of the
         | loosely grammar-like structure mentioned in OP. The algorithmic
         | operations they play with are not very well defined but the
         | background theory is sound, and closely reflects what music
         | theorists and composers in general have written about the
         | subject in the 500 years or more it has been seriously studied.
         | 
         | As for deep learning models which create good contrapuntal
         | music, see e.g. 'Biaxial RNN'
         | https://github.com/danieldjohnson/biaxial-rnn-music-composit...
         | by Daniel D. Johnson, who is now at Google Brain but wrote this
         | as an independent(!) researcher. (Note that the existing code
         | requires Python 2.x It would be interesting to forward-port it
         | so it can work with Python 3.x and a maintained version of
         | Theano. Replicating the model using Tensorflow would also be
         | quite worthwhile.)
         | 
         | If you're interested in Bach's work specifically, the "BachBot"
         | and "DeepBach" projects are also interesting but less
         | accessible.
         | 
         | Example output for all of these models can be found on the
         | Internet, just look around for it. The proprietary system AIVA
         | is also worth mentioning because even though it's so
         | proprietary and secretive, the compelling and "serendipitous"
         | music it manages to come up with is a tell-tale sign that it's
         | actually doing well-founded deep learning stuff behind the
         | scenes, much like the aforementioned open systems. Note that
         | much of the released output has been orchestrated (AFAICT)
         | manually by humans, but at some point I was able to find some
         | piano-format reductions that are most likely _very_ close to
         | what the AI actually created, somewhere on the official site.
        
           | p1esk wrote:
           | Deep learning needs a lot if training data. There's not
           | enough MIDI encoded music to train something like a GPT-3
           | model to generate MIDI sequences. A better way is to train on
           | and generate raw audio, see OpenAI JukeBox. Unfortunately
           | it's extremely compute intensive (even compared to GPT-3), so
           | it will probably be a few more years until they (or some
           | other big player) releases JukeBox-2.
        
             | zozbot234 wrote:
             | The amount of data you need depends on the model
             | architecture you're using. A generic model like GPT-3 is
             | neither here nor there, but something specifically intended
             | for music can make do with very little data.
        
               | p1esk wrote:
               | What do you mean "neither here nor there"?
        
               | zozbot234 wrote:
               | The structure of something like GPT-3 is far too weak and
               | general to achieve good results for something as
               | structurally complex as music. It's designed to generate
               | text - and then mostly natural language text. Music is
               | very different, as OP hints in the linked post.
        
               | p1esk wrote:
               | I thought you wanted to use deep learning. In DL
               | transformers are the best we got currently. Both JukeBox
               | and MuseNet use transformers. What makes you think they
               | are not up to the task?
        
         | whiddershins wrote:
         | I don't agree at all, and it's not even experimental.
         | 
         | And I think that is not a very nice thing to say about other
         | people's work.
        
         | TheOtherHobbes wrote:
         | The reason the end result is pretty terrible is because
         | classical harmony and melody are closely related, and you can't
         | job-lot-replace one without ruining the other.
         | 
         | This project is quite similar to something I've been working
         | on, but I realised early on that you can't split up features
         | like this and get credible results - credible meaning
         | "appropriate for the style grammar."
         | 
         | It's a bit - only a bit, but let's go with it - like trying to
         | generate sentences by swapping out nouns and adverbs. You end
         | up with something that is grammatically correct in theory but
         | makes no sense in practice.
         | 
         | Classical music particularly is fundamentally _integrated_ in a
         | way that textbook analysis doesn 't fully explore.
        
         | klyrs wrote:
         | "Pretty terrible" is awfully strong. I've heard a lot of
         | _terrible_ music and this doesn 't make that cut. What you're
         | reading is a nice writeup of some theory, with a worked example
         | to showcase how to utilize some features of a library which is
         | a work in progress. The author even notes that the music is
         | simplified for the example. It isn't meant to _be_ Bethoven. It
         | isn 't even AI. If you want to see AI, other people have done
         | that already.
         | 
         | What's cool about this library isn't the quality of the (midi,
         | retch) output -- what's cool is the actual Python library
         | behind it, and the writeup, which are both super easy to read
         | and follow.
        
       ___________________________________________________________________
       (page generated 2022-02-13 23:00 UTC)