W4 A3 | ValueError: not enough values to unpack (expected 2, got 0)

When I was trying to run this line of code:

X, Y, n_values, indices_values, chords = load_music_utils('data/original_metheny.mid')

I got:

/var/folders/xw/b17c_b31565_0dq3hp8373kr0000gn/T/ipykernel_24786/325991792.py in <module>
----> 1 X, Y, n_values, indices_values, chords = load_music_utils('data/original_metheny.mid')
      2 print('number of training examples:', X.shape[0])
      3 print('Tx (length of sequence):', X.shape[1])
      4 print('total # of unique values:', n_values)
      5 print('shape of X:', X.shape)

~/projects/ml_notes/dl_course/exercises/05_Sequence_Models/03/data_utils.py in load_music_utils(file)
     18 
     19 def load_music_utils(file):
---> 20     chords, abstract_grammars = get_musical_data(file)
     21     corpus, tones, tones_indices, indices_tones = get_corpus_data(abstract_grammars)
     22     N_tones = len(set(corpus))

~/projects/ml_notes/dl_course/exercises/05_Sequence_Models/03/preprocess.py in get_musical_data(data_fn)
    133 def get_musical_data(data_fn):
    134 
--> 135     measures, chords = __parse_midi(data_fn)
    136     abstract_grammars = __get_abstract_grammars(measures, chords)
    137 

~/projects/ml_notes/dl_course/exercises/05_Sequence_Models/03/preprocess.py in __parse_midi(data_fn)
     27     # Get melody part, compress into single voice.
     28     melody_stream = midi_data[5]     # For Metheny piece, Melody is Part #5.
---> 29     melody1, melody2 = melody_stream.getElementsByClass(stream.Voice)
     30     for j in melody2:
     31         melody1.insert(j.offset, j)

ValueError: not enough values to unpack (expected 2, got 0)

Didn’t make any change to the code. I found melody_stream only contains a list of Measures and no Voice is in the stream.

Any idea why this happens?

Course 5 Week 4 Assignment 3 is not possible. Week 4 has only one assignment.

I suspect you’re referring to Week 1 Assignment 3 (Jazz)

I have no idea why you would see those errors. None of those functions or files seem to have been updated recently.

Hi sorry you are right, it is Course 5 Week 1 Assignment 3.

It turns out that it was because I was using music21==7.1.0

By downgrading to music21==5.1.0 this issue is fixed.

3 Likes

It actually works with higher version 6.5.0 for music21. Ive just checked on coursera notebooks.

1 Like

In my computer I installed the versions but the same the error appears

I’m working locally (MacBook Pro, M1) and I can confirm it works with version 6.

I did:

conda install music21=6

Which installed 6.7.1.

2 Likes