# What is branch factor for beam search in RNNs like TensorFlow's Magenta?

TensorFlow's Magenta melody generation module has a parameter for branch_factor1. What is it?

Branch factor in beam search refers to average number of branches at each level of a search tree. When predicting a sequence in an LSTM model, such as note selection in melody generation, $b$ branches will be decoded. Increasing the branch factor from 1 to 4 in the call to melody_rnn_generate will maintain the average number of branches to be at $b$.

Specifically for Magenta, it generates 4 branches for each event sequence. It will increase the accuracy of the prediction at the expense of time, and in melody creation at the risk of getting stuck in a local optimum. For example, increasing the branch factor from 1 to 2 decreased the average negative log-likelihood of a melody generation implementation from 36 to 8, but also made the sequence prediction more dependent on the primer sequence (repeating the primer note).