Skip to content

Instantly share code, notes, and snippets.

View craffel's full-sized avatar

Colin Raffel craffel

View GitHub Profile
@craffel
craffel / draw_neural_net.py
Created January 10, 2015 04:59
Draw a neural network diagram with matplotlib!
import matplotlib.pyplot as plt
def draw_neural_net(ax, left, right, bottom, top, layer_sizes):
'''
Draw a neural network cartoon using matplotilb.
:usage:
>>> fig = plt.figure(figsize=(12, 12))
>>> draw_neural_net(fig.gca(), .1, .9, .1, .9, [4, 7, 2])
@craffel
craffel / popcount_array.pyx
Last active October 11, 2022 20:48 — forked from aldro61/popcount_array.pyx
Popcount of a numpy array of integers of any dtype
"""
Functions for computing the population count (aka Hamming weight) of an array
in-place using the built-in popcount routine.
Works with any integer datatype 64 bit-width or smaller.
Compile with gcc flag -mpopcnt
Adapted from
https://gist.github.com/aldro61/f604a3fa79b3dec5436a by Alexandre Drouin
"""
import numpy as np
cimport numpy as np
@craffel
craffel / Tutorial.ipynb
Created October 21, 2017 04:52
pretty_midi tutorial (draft)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@craffel
craffel / mrr.py
Created January 19, 2016 02:47
Compute mean reciprocal rank between two sets of feature vectors
def mean_reciprocal_rank(X, Y, indices, metric='hamming'):
''' Computes the mean reciprocal rank of the correct match
Assumes that X[n] should be closest to Y[n]
Default uses hamming distance
:parameters:
- X : np.ndarray, shape=(n_examples, n_features)
Data matrix in X modality
- Y : np.ndarray, shape=(n_examples, n_features)
Data matrix in Y modality
- indices : np.ndarray
@craffel
craffel / nqyn-dev.tsv
Created August 20, 2020 12:40
Yes/no questions in Natural Questions
dominant alleles are always the most common allele in a population NO
is there a basketball team in las vegas YES
extinction can be the result of habitat fragmentation YES
is area code 808 a toll free number NO
does a south african passport need a visa for singapore NO
does newman's own really give all profits to charity YES
is the son of the beast still at kings island NO
all types of joints allow for the same range of motion NO
do ghanaians need visa to go to singapore NO
is the right to life liberty and the pursuit of happiness in the constitution NO
@craffel
craffel / gist:50a422f431350f0b3b09
Last active May 28, 2018 23:40
Faster pretty_midi Fluidsynth method
import tempfile
import subprocess
import os
import pretty_midi
import librosa
def fast_fluidsynth(m, fs):
'''
Faster fluidsynth synthesis using the command-line program
instead of pyfluidsynth.
@craffel
craffel / gist:76924fd211720412c19327cfb8f0f5e2
Created June 21, 2017 19:20
Vim regex for replacing all commas not followed by space with commas followed by space
:%s/,\([^ ]\)/, \1/g
@craffel
craffel / clean_clean_midis.py
Last active April 24, 2016 23:34
Scripts used for generating the clean MIDI subset, as used in https://github.com/craffel/midi-dataset
import os
os.chdir('..')
import sys
sys.path.append(os.getcwd())
import normalize_names
import pickle
with open('data/Clean MIDIs-md5_to_artist_title.pickle') as f:
md5_to_artist_title = pickle.load(f)
@craffel
craffel / Count github LOC.ipynb
Created April 24, 2016 22:24
Count your total contributions on GitHub of a certain filetype (a hack)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@craffel
craffel / get_live_uspop2002.py
Created December 2, 2015 19:30
Get liveness score for each entry in uspop2002
"""
Create a tab-separated value file for uspop2002 entries which includes each
track's Echo Nest "loudness" score
"""
import pyen
import os
import time
# Put your Echo Nest API key in a file called .echonest_key