Module Expr Str ImportFrom alias Import alias ImportFrom alias Import alias identifier ImportFrom alias ImportFrom alias ImportFrom alias Import alias Expr Str FunctionDef arguments args NameParam NameParam defaults Num body Assign NameStore BinOpDiv Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore BinOpDiv Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Return Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr Num NameLoad Num decorator_list Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Assign NameStore SubscriptLoad Call AttributeLoad NameLoad attr NameLoad keyword Num Index Num Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad NameLoad Index NameLoad Return NameLoad decorator_list Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults body Assign NameStore Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Num BinOpSub Call NameLoad NameLoad NameLoad Assign NameStore SubscriptLoad NameLoad Slice NameLoad BinOpAdd NameLoad NameLoad Assign NameStore Num While CompareLtE NameLoad Num body Assign NameStore Call AttributeLoad NameLoad attr TupleLoad Num NameLoad Call NameLoad NameLoad For TupleStore NameStore NameStore Call NameLoad NameLoad body If UnaryOpNot CompareIn NameLoad NameLoad body Expr Call NameLoad NameLoad Assign SubscriptStore NameLoad Index TupleLoad Num NameLoad SubscriptLoad NameLoad Index NameLoad Num Assign NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad If CompareLt NameLoad Num body Assign NameStore Num While BoolOpOr CompareEq SubscriptLoad Call AttributeLoad NameLoad attr Str Index Num Str CompareNotEq Call NameLoad Call AttributeLoad NameLoad attr Str Num body If CompareGtE NameLoad NameLoad body Expr Call NameLoad Str NameLoad Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Num Call NameLoad NameLoad Assign NameStore SubscriptLoad Call AttributeLoad SubscriptLoad NameLoad Index NameLoad attr Str Index Num orelse Assign NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad AugAssignAdd NameStore Num Assign NameStore SubscriptLoad NameLoad Slice Num Expr Call AttributeLoad NameLoad attr NameLoad If CompareGt NameLoad Num body AugAssignAdd NameStore Str AugAssignAdd NameStore NameLoad Assign NameStore Call NameLoad SubscriptLoad Call AttributeLoad NameLoad attr Str Index Num AugAssignAdd NameStore NameLoad Return NameLoad decorator_list Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign NameStore Num Assign TupleStore NameStore NameStore Call NameLoad NameLoad Assign TupleStore NameStore NameStore NameStore NameStore Call NameLoad NameLoad Expr Call NameLoad Str Call NameLoad NameLoad Expr Call NameLoad Str Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Num Assign NameStore Call NameLoad NameLoad For NameStore Call NameLoad Num NameLoad body Assign NameStore Call AttributeLoad NameLoad attr For NameStore SubscriptLoad NameLoad Index NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod AttributeLoad NameLoad attr Num NameLoad Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr Str Str attr Str Str Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad NameLoad Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad Expr Call NameLoad BinOpMod Str Call NameLoad ListComp NameLoad comprehension NameStore NameLoad Call NameLoad NameLoad AttributeLoad NameLoad attr For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad AttributeLoad NameLoad attr NameLoad For NameStore NameLoad body Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad AttributeLoad NameLoad attr NameLoad AugAssignAdd NameStore Num Expr Call AttributeLoad NameLoad attr Num Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Lambda arguments args NameParam defaults Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad attr Expr Call NameLoad NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Str Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr decorator_list Expr Str FunctionDef arguments args NameParam defaults body TryExcept body Assign NameStore Call NameLoad SubscriptLoad NameLoad Index Num handlers ExceptHandler body Assign NameStore Num Assign NameStore BinOpAdd Str Str Assign NameStore BinOpAdd Str Call NameLoad NameLoad If CompareEq NameLoad Num body AugAssignAdd NameStore Str orelse AugAssignAdd NameStore Str Expr Call NameLoad NameLoad NameLoad NameLoad decorator_list Expr Str If CompareEq NameLoad Str body Import alias Expr Call NameLoad AttributeLoad NameLoad attr
N/A N/A 
Author:     Ji-Sung Kim
Project:    deepjazz
Purpose:    Generate jazz using a deep learning model (LSTM in deepjazz).

Some code adapted from Evan Chow's jazzml, https://github.com/evancchow/jazzml 
with express permission.

Code was built while significantly referencing public examples from the
Keras documentation on GitHub:
https://github.com/fchollet/keras/blob/master/examples/lstm_text_generation.py

GPU run command:
    THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python generator.py [# of epochs]

    Note: running Keras/Theano on GPU is formally supported for only NVIDIA cards (CUDA backend).
 __future__ print_function N/A sys music21 * N/A numpy np grammar * preprocess * qa * N/A lstm N/A  Helper function to sample an index from a probability array  __sample N/A N/A a temperature N/A 1.0 N/A N/A a N/A N/A N/A np log a temperature N/A a N/A N/A N/A np exp a N/A N/A np sum N/A N/A np exp a N/A N/A N/A np argmax N/A N/A N/A np random multinomial 1 a 1 N/A N/A  Helper function to generate a predicted value from a given matrix  __predict N/A N/A model x indices_val diversity N/A N/A N/A preds N/A N/A N/A model predict x verbose 0 N/A 0 N/A next_index N/A __sample preds diversity N/A next_val N/A indices_val N/A next_index N/A next_val N/A N/A  Helper function which uses the given model to generate a grammar sequence 
    from a given corpus, indices_val (mapping), abstract_grammars (list), 
    and diversity floating point value.  __generate_grammar N/A N/A model corpus abstract_grammars values val_indices indices_val max_len max_tries diversity N/A N/A N/A curr_grammar N/A start_index N/A N/A N/A np random randint 0 N/A N/A len corpus max_len N/A sentence N/A corpus N/A start_index N/A start_index max_len N/A running_length 0.0 N/A N/A running_length 4.1 N/A N/A x N/A N/A np zeros N/A 1 max_len N/A len values N/A N/A t val N/A enumerate sentence N/A N/A N/A N/A val val_indices N/A N/A N/A print val N/A N/A x N/A N/A 0 t N/A val_indices N/A val 1.0 N/A next_val N/A __predict model x indices_val diversity N/A N/A running_length 1e-05 N/A N/A tries 0 N/A N/A N/A N/A N/A N/A next_val split , N/A 0 R N/A N/A len N/A N/A next_val split , 2 N/A N/A N/A tries max_tries N/A N/A N/A print Gave up on first note generation after max_tries tries N/A rand N/A N/A N/A np random randint 0 N/A len abstract_grammars N/A next_val N/A N/A N/A N/A abstract_grammars N/A rand split N/A 0 N/A N/A next_val N/A __predict model x indices_val diversity N/A tries 1 N/A sentence N/A sentence N/A 1 N/A N/A N/A sentence append next_val N/A N/A running_length 1e-05 N/A N/A curr_grammar N/A curr_grammar next_val N/A length N/A float N/A N/A N/A next_val split , N/A 1 N/A running_length length N/A curr_grammar N/A N/A  Generates musical sequence based on the given data filename and settings.
    Plays then stores (MIDI file) the generated output.  generate N/A N/A data_fn out_fn N_epochs N/A N/A N/A max_len 20 N/A max_tries 1000 N/A diversity 0.5 N/A bpm 130 N/A N/A chords abstract_grammars N/A get_musical_data data_fn N/A N/A corpus values val_indices indices_val N/A get_corpus_data abstract_grammars N/A N/A print corpus length: N/A len corpus N/A N/A print total # of values: N/A len values N/A model N/A N/A lstm build_model corpus corpus val_indices val_indices max_len max_len N_epochs N_epochs N/A out_stream N/A N/A stream Stream N/A curr_offset 0.0 N/A loopEnd N/A len chords N/A loopIndex N/A range 1 loopEnd N/A N/A curr_chords N/A N/A stream Voice N/A j N/A chords N/A loopIndex N/A N/A N/A N/A curr_chords insert N/A N/A j offset 4 j N/A curr_grammar N/A __generate_grammar model model corpus corpus abstract_grammars abstract_grammars values values val_indices val_indices indices_val indices_val max_len max_len max_tries max_tries diversity diversity N/A curr_grammar N/A N/A N/A N/A curr_grammar replace  A  C replace  X  C N/A curr_grammar N/A prune_grammar curr_grammar N/A curr_notes N/A unparse_grammar curr_grammar curr_chords N/A curr_notes N/A prune_notes curr_notes N/A curr_notes N/A clean_up_notes curr_notes N/A N/A print N/A After pruning: %s notes N/A len N/A i N/A i curr_notes N/A isinstance i N/A note Note N/A m curr_notes N/A N/A N/A N/A out_stream insert N/A curr_offset N/A m offset m N/A mc curr_chords N/A N/A N/A N/A out_stream insert N/A curr_offset N/A mc offset mc N/A curr_offset 4.0 N/A N/A N/A out_stream insert 0.0 N/A N/A tempo MetronomeMark number bpm N/A play N/A N/A N/A x N/A N/A N/A N/A N/A N/A midi realtime StreamPlayer x play N/A N/A play out_stream N/A mf N/A N/A N/A midi translate streamToMidiFile out_stream N/A N/A N/A mf open out_fn wb N/A N/A N/A mf write N/A N/A N/A mf close N/A N/A  Runs generate() -- generating, playing, then storing a musical sequence --
    with the default Metheny file.  main N/A N/A args N/A N/A N/A N/A N/A N_epochs N/A int N/A args N/A 1 N/A N/A N/A N/A N_epochs 128 N/A data_fn N/A midi/ original_metheny.mid N/A out_fn N/A midi/deepjazz_on_metheny... N/A str N_epochs N/A N/A N_epochs 1 N/A N/A out_fn _epoch.midi N/A N/A out_fn _epochs.midi N/A N/A generate data_fn out_fn N_epochs N/A N/A  If run as script, execute main  N/A N/A __name__ __main__ N/A N/A sys N/A N/A main N/A sys argv