The piano keyboard has 88 keys: enter image description here

I would like to encode one note or one chord in 88 bit array. I do this, for example: A4 is 0000000000000000000000000000000000000000000000000000000001000000000000000000000000000000

Next I convert this number to decimal. When I have chord the final number is really big. The problem is when I put this big number into array from NumPy I gets:

note_data = np.array(note_data, dtype=np.int64)
OverflowError: Python int too large to convert to C long

My point is to feed recurrent neural netowrk this kind of data or maybe is better representation on music notes into numbers?


Another example of encode C3 note:

C3 = np.array([0000000000000000000000000001000000000000000000000000000000000000000000000000000000000000], dtype=int)

and error sitll the same:

OverflowError: Python int too large to convert to C long

It's possible to reduce this error?


That seems like a bad way to encode the information. A C chord and a C7 chord would be very different numbers even though they are similar conceptually.

I would take your idea, but instead of smashing the information into a single int, make your input a binary vector of length 88 created in the way you describe. In this way, a C and C7 will have similar inputs, differing in only one location of the vector.

As a simplified one octave example going from C to B:

C : [1,0,0,0,1,0,0,1,0,0,0,0]
C7: [1,0,0,0,1,0,0,1,0,0,1,0]

This kind of encoding is making use of “dummy variables”. It is like the “Bag of Words” encoding used a lot in Natural Language Processing.

  • $\begingroup$ Ok, Thank you for reply. I known One hot encoding method. But in which way can I encode chord like C, E, G on one hot encoding method? $\endgroup$
    – lukassz
    Jan 30 '19 at 22:15
  • $\begingroup$ binary vector of length 88 is not too long as I desctibed? Yes, C and C7 is similar but C7 have more information it also have E and G. $\endgroup$
    – lukassz
    Jan 30 '19 at 22:19
  • $\begingroup$ No, a vector of length 88 should be no problem at all. $\endgroup$
    – kbrose
    Jan 31 '19 at 13:37
  • $\begingroup$ I made an example in one octave. $\endgroup$
    – kbrose
    Jan 31 '19 at 13:46
  • $\begingroup$ ok I got your point I did this before asking on datascience. If we have 88 binary vector representing single chord. C chord and C7 would be very diffrent numbers. If we have input vector of length 12 C is 2192 and C7 2194 its close. How about octaves? I decide to test with 88 input because I can place chord in diffrent octaves. Now I known it's bad idea. In which way can I represent octave? As concatenation 12 bits for notes and 8 bits of octave? $\endgroup$
    – lukassz
    Feb 2 '19 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.