(self, chord_tuples, key_tuples)
return control_seqs
Map chord and/or key tuples to control tensors.
Map chord and/or key tuples to control tensors.
Map chord and / or key tuples to control tensors .
def _chords_and_keys_to_controls(self, chord_tuples, key_tuples):
    """Map chord and/or key tuples to control tensors."""
    control_seqs = []

    # Use zip_longest here because chord_tuples and key_tuples should either be:
    #   a) a list of tuples, with chord_tuples and key_tuples the same shape
    #   b) the empty list
    for ct, kt in itertools.zip_longest(chord_tuples, key_tuples):
      controls = []

      if ct is not None:
        try:
          chord_tokens = [self._chord_encoding.encode_event(e) for e in ct]
          if self.end_token:
            # Repeat the last chord instead of using a special token;
            # otherwise the model may learn to rely on the special token to
            # detect endings.
            if chord_tokens:
              chord_tokens.append(chord_tokens[-1])
            else:
              chord_tokens.append(
                  self._chord_encoding.encode_event(note_seq.NO_CHORD))
        except (note_seq.ChordSymbolError, note_seq.ChordEncodingError):
          return []
        controls.append(np_onehot(
            chord_tokens, self._chord_encoding.num_classes,
            self.control_dtype))

      if kt is not None:
        if self.end_token:
          # Repeat the last key. If the sequence is empty, just pick randomly.
          if kt:
            kt.append(kt[-1])
          else:
            kt.append(np.random.choice(range(12)))
        controls.append(np_onehot(kt, 12, self.control_dtype))

      # Concatenate controls (chord and/or key) depthwise. The resulting control
      # tensor should be one of:
      #   a) a one-hot-encoded chord (if not conditioning on key)
      #   b) a one-hot-encoded key (if not conditioning on chord)
      #   c) both (a) and (b), concatenated depthwise
      control_seqs.append(np.concatenate(controls, axis=1))

    return control_seqs
def _chords_and_keys_to_controls ( self , chord_tuples , key_tuples ) : control_seqs = [ ] # Use zip_longest here because chord_tuples and key_tuples should either be: #   a) a list of tuples, with chord_tuples and key_tuples the same shape #   b) the empty list for ct , kt in itertools . zip_longest ( chord_tuples , key_tuples ) : controls = [ ] if ct is not None : try : chord_tokens = [ self . _chord_encoding . encode_event ( e ) for e in ct ] if self . end_token : # Repeat the last chord instead of using a special token; # otherwise the model may learn to rely on the special token to # detect endings. if chord_tokens : chord_tokens . append ( chord_tokens [ - 1 ] ) else : chord_tokens . append ( self . _chord_encoding . encode_event ( note_seq . NO_CHORD ) ) except ( note_seq . ChordSymbolError , note_seq . ChordEncodingError ) : return [ ] controls . append ( np_onehot ( chord_tokens , self . _chord_encoding . num_classes , self . control_dtype ) ) if kt is not None : if self . end_token : # Repeat the last key. If the sequence is empty, just pick randomly. if kt : kt . append ( kt [ - 1 ] ) else : kt . append ( np . random . choice ( range ( 12 ) ) ) controls . append ( np_onehot ( kt , 12 , self . control_dtype ) ) # Concatenate controls (chord and/or key) depthwise. The resulting control # tensor should be one of: #   a) a one-hot-encoded chord (if not conditioning on key) #   b) a one-hot-encoded key (if not conditioning on chord) #   c) both (a) and (b), concatenated depthwise control_seqs . append ( np . concatenate ( controls , axis = 1 ) ) return control_seqs