{ "metadata": { "name": "", "signature": "sha256:3f785632d8399faeb298103405c9f9b70f1240eca928b05d3549f7900d5465fb" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Now, it's time to do some deep learning. Recall that a RBM (Restricted Boltzmann Machine) takes in a binary vector, and you can use it in the SKLearn Pipeline with a classifier. You'll want to read in Oscar's original data as an array of bitwise note vectors, and from there build the RBM to predict chords (the y's, perhaps build the chord bank and assign a unique number to each). After that, given a note vector (maybe plural?), you should be able to predict the chords for a note (notes?)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from collections import defaultdict\n", "from sklearn.neural_network import BernoulliRBM\n", "import pandas as pd\n", "import numpy as np" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 28 }, { "cell_type": "code", "collapsed": false, "input": [ "# Extract chords into unique ids, e.g. 1, 2, 3, 4, 5\n", "allchords = defaultdict()\n", "with open(\"oscar2chords_extract.txt\", 'rb') as f:\n", " assert len(allchords) == len(set(allchords)) # ensure no duplicate chords\n", " for ix, line in enumerate(f):\n", " allchords[ix] = line.rstrip()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "# Read in Oscar's data.\n", "vectors = []\n", "notedata = pd.read_csv(open(\"oscar2notes.txt\", 'rb'), skiprows=2)\n", "allnotes = []\n", "for note, octave in zip(notedata[\"Note/Rest\"], notedata[\"Octave\"]):\n", " allnotes.append(\"%s%s\" % (note, octave))\n", "print allnotes[:10]\n", "notedata.head()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['B3', 'A5', 'F4', 'G4', 'F4', 'B-5', 'B3', 'B-5', 'C4', 'C5']\n" ] }, { "html": [ "
\n", " | Note/Rest | \n", "Octave | \n", "Len | \n", "Offset | \n", "
---|---|---|---|---|
0 | \n", "B | \n", "3 | \n", "0.500000 | \n", "12.625 | \n", "
1 | \n", "A | \n", "5 | \n", "0.250000 | \n", "15.000 | \n", "
2 | \n", "F | \n", "4 | \n", "3.125000 | \n", "16.000 | \n", "
3 | \n", "G | \n", "4 | \n", "0.666667 | \n", "20.625 | \n", "
4 | \n", "F | \n", "4 | \n", "1.250000 | \n", "23.875 | \n", "
5 rows \u00d7 4 columns
\n", "