class_docstr: Class for RNN event sequence generation models.
  
  Currently this class only supports generation, of both event sequences and
  note sequences (via event sequences). Support for model training will be added
  at a later time.
class_docstr_tok: ["Class","for","RNN","event","sequence","generation","models",".","Currently","this","class","only","supports","generation",",","of","both","event","sequences","and","note","sequences","(","via","event","sequences",")",".","Support","for","model","training","will","be","added","at","a","later","time","."]
docstr: Extends a list of event sequences by a single step each.
  
  This method modifies the event sequences in place. It also returns the
  modified event sequences and updated model states and log-likelihoods.
  
  Args:
    event_sequences: A list of event sequence objects, which are extended by
        this method.
    model_states: A list of model states, each of which contains model inputs
        and initial RNN states.
    logliks: A list containing the current log-likelihood for each event
        sequence.
    temperature: The softmax temperature.
    extend_control_events_callback: A function that takes three arguments: a
        current control event sequence, a current generated event sequence,
        and the control state. The function should a) extend the control event
        sequence to be one longer than the generated event sequence (or do
        nothing if it is already at least this long), and b) return the
        resulting control state.
    modify_events_callback: An optional callback for modifying the event list.
        Can be used to inject events rather than having them generated. If not
        None, will be called with 3 arguments after every event: the current
        EventSequenceEncoderDecoder, a list of current EventSequences, and a
        list of current encoded event inputs.
  
  Returns:
    event_sequences: A list of extended event sequences. These are modified in
        place but also returned.
    final_states: A list of resulting model states, containing model inputs
        for the next step along with RNN states for each event sequence.
    logliks: A list containing the updated log-likelihood for each event
        sequence.
docstr_tok: ["Extends","a","list","of","event","sequences","by","a","single","step","each",".","This","method","modifies","the","event","sequences","in","place",".","It","also","returns","the","modified","event","sequences","and","updated","model","states","and","log-likelihoods",".","Args",":","event_sequences",":","A","list","of","event","sequence","objects",",","which","are","extended","by","this","method",".","model_states",":","A","list","of","model","states",",","each","of","which","contains","model","inputs","and","initial","RNN","states",".","logliks",":","A","list","containing","the","current","log-likelihood","for","each","event","sequence",".","temperature",":","The","softmax","temperature",".","extend_control_events_callback",":","A","function","that","takes","three","arguments",":","a","current","control","event","sequence",",","a","current","generated","event","sequence",",","and","the","control","state",".","The","function","should","a",")","extend","the","control","event","sequence","to","be","one","longer","than","the","generated","event","sequence","(","or","do","nothing","if","it","is","already","at","least","this","long",")",",","and","b",")","return","the","resulting","control","state",".","modify_events_callback",":","An","optional","callback","for","modifying","the","event","list",".","Can","be","used","to","inject","events","rather","than","having","them","generated",".","If","not","None",",","will","be","called","with","3","arguments","after","every","event",":","the","current","EventSequenceEncoderDecoder",",","a","list","of","current","EventSequences",",","and","a","list","of","current","encoded","event","inputs",".","Returns",":","event_sequences",":","A","list","of","extended","event","sequences",".","These","are","modified","in","place","but","also","returned",".","final_states",":","A","list","of","resulting","model","states",",","containing","model","inputs","for","the","next","step","along","with","RNN","states","for","each","event","sequence",".","logliks",":","A","list","containing","the","updated","log-likelihood","for","each","event","sequence","."]
code: def _generate_step(
      self,
      event_sequences,
      model_states,
      logliks,
      temperature,
      extend_control_events_callback=None,
      modify_events_callback=None,
  ):
      """Extends a list of event sequences by a single step each.
  
      This method modifies the event sequences in place. It also returns the
      modified event sequences and updated model states and log-likelihoods.
  
      Args:
        event_sequences: A list of event sequence objects, which are extended by
            this method.
        model_states: A list of model states, each of which contains model inputs
            and initial RNN states.
        logliks: A list containing the current log-likelihood for each event
            sequence.
        temperature: The softmax temperature.
        extend_control_events_callback: A function that takes three arguments: a
            current control event sequence, a current generated event sequence,
            and the control state. The function should a) extend the control event
            sequence to be one longer than the generated event sequence (or do
            nothing if it is already at least this long), and b) return the
            resulting control state.
        modify_events_callback: An optional callback for modifying the event list.
            Can be used to inject events rather than having them generated. If not
            None, will be called with 3 arguments after every event: the current
            EventSequenceEncoderDecoder, a list of current EventSequences, and a
            list of current encoded event inputs.
  
      Returns:
        event_sequences: A list of extended event sequences. These are modified in
            place but also returned.
        final_states: A list of resulting model states, containing model inputs
            for the next step along with RNN states for each event sequence.
        logliks: A list containing the updated log-likelihood for each event
            sequence.
      """
      # Split the sequences to extend into batches matching the model batch size.
      batch_size = self._batch_size()
      num_seqs = len(event_sequences)
      num_batches = int(np.ceil(num_seqs / float(batch_size)))
  
      # Extract inputs and RNN states from the model states.
      inputs = [model_state.inputs for model_state in model_states]
      initial_states = [
          model_state.rnn_state for model_state in model_states
      ]
  
      # Also extract control sequences and states.
      control_sequences = [
          model_state.control_events for model_state in model_states
      ]
      control_states = [
          model_state.control_state for model_state in model_states
      ]
  
      final_states = []
      logliks = np.array(logliks, dtype=np.float32)
  
      # Add padding to fill the final batch.
      pad_amt = -len(event_sequences) % batch_size
      padded_event_sequences = event_sequences + [
          copy.deepcopy(event_sequences[-1]) for _ in range(pad_amt)
      ]
      padded_inputs = inputs + [inputs[-1]] * pad_amt
      padded_initial_states = (
          initial_states + [initial_states[-1]] * pad_amt
      )
  
      for b in range(num_batches):
          i, j = b * batch_size, (b + 1) * batch_size
          pad_amt = max(0, j - num_seqs)
          # Generate a single step for one batch of event sequences.
          (
              batch_final_state,
              batch_loglik,
          ) = self._generate_step_for_batch(
              padded_event_sequences[i:j],
              padded_inputs[i:j],
              state_util.batch(padded_initial_states[i:j], batch_size),
              temperature,
          )
          final_states += state_util.unbatch(
              batch_final_state, batch_size
          )[: j - i - pad_amt]
          logliks[i : j - pad_amt] += batch_loglik[: j - i - pad_amt]
  
      # Construct inputs for next step.
      if extend_control_events_callback is not None:
          # We are conditioning on control sequences.
          for idx in range(len(control_sequences)):
              # Extend each control sequence to ensure that it is longer than the
              # corresponding event sequence.
              control_states[idx] = extend_control_events_callback(
                  control_sequences[idx],
                  event_sequences[idx],
                  control_states[idx],
              )
          next_inputs = self._config.encoder_decoder.get_inputs_batch(
              control_sequences, event_sequences
          )
      else:
          next_inputs = self._config.encoder_decoder.get_inputs_batch(
              event_sequences
          )
  
      if modify_events_callback:
          # Modify event sequences and inputs for next step.
          modify_events_callback(
              self._config.encoder_decoder, event_sequences, next_inputs
          )
  
      model_states = [
          ModelState(
              inputs=inputs,
              rnn_state=final_state,
              control_events=control_events,
              control_state=control_state,
          )
          for inputs, final_state, control_events, control_state in zip(
              next_inputs,
              final_states,
              control_sequences,
              control_states,
          )
      ]
  
      return event_sequences, model_states, logliks
  
imports: import collections
  import copy
  import functools
  from magenta.common import beam_search
  from magenta.common import state_util
  from magenta.contrib import training
  from magenta.models.shared import events_rnn_graph
  from magenta.models.shared import model
  import note_seq
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling the EventSequenceRnnModel obj's underlying member method code with example usage: obj._generate_step(event_sequences, model_states, logliks, temperature, extend_control_events_callback, modify_events_callback) and returns: event_sequences,  model_states,  logliks