class_docstr: Implements a recurrent DQN designed to produce melody sequences.
class_docstr_tok: ["Implements","a","recurrent","DQN","designed","to","produce","melody","sequences","."]
docstr: Detects if a motif was just played and if so, returns it.
  
  A motif should contain at least three distinct notes that are not note_on
  or note_off, and occur within the course of one bar.
  
  Args:
    composition: The composition in which the function will look for a
      recent motif. Defaults to the model's composition.
    bar_length: The number of notes in one bar.
  Returns:
    None if there is no motif, otherwise the motif in the same format as the
    composition.
docstr_tok: ["Detects","if","a","motif","was","just","played","and","if","so",",","returns","it",".","A","motif","should","contain","at","least","three","distinct","notes","that","are","not","note_on","or","note_off",",","and","occur","within","the","course","of","one","bar",".","Args",":","composition",":","The","composition","in","which","the","function","will","look","for","a","recent","motif",".","Defaults","to","the","model","'s","composition",".","bar_length",":","The","number","of","notes","in","one","bar",".","Returns",":","None","if","there","is","no","motif",",","otherwise","the","motif","in","the","same","format","as","the","composition","."]
code: def detect_last_motif(self, composition=None, bar_length=8):
      """Detects if a motif was just played and if so, returns it.
  
      A motif should contain at least three distinct notes that are not note_on
      or note_off, and occur within the course of one bar.
  
      Args:
        composition: The composition in which the function will look for a
          recent motif. Defaults to the model's composition.
        bar_length: The number of notes in one bar.
      Returns:
        None if there is no motif, otherwise the motif in the same format as the
        composition.
      """
      if composition is None:
          composition = self.composition
  
      if len(composition) < bar_length:
          return None, 0
  
      last_bar = composition[-bar_length:]
  
      actual_notes = [
          a for a in last_bar if a not in (NO_EVENT, NOTE_OFF)
      ]
      num_unique_notes = len(set(actual_notes))
      if num_unique_notes >= 3:
          return last_bar, num_unique_notes
      else:
          return None, num_unique_notes
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  import random
  import urllib
  from magenta.models.rl_tuner import note_rnn_loader
  from magenta.models.rl_tuner import rl_tuner_eval_metrics
  from magenta.models.rl_tuner import rl_tuner_ops
  import matplotlib.pyplot
  from note_seq import melodies_lib
  from note_seq import midi_io
  import numpy
  import scipy.special
  from six.moves import range
  from six.moves import reload_module
  from six.moves import urllib
  import tensorflow.compat.v1
label_desc: Use image node_id 26 for calling the RLTuner obj's underlying member method code with example usage: obj.detect_last_motif(composition, bar_length) and returns: None,  int, last_bar,  num_unique_notes, None,  num_unique_notes