Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@kastnerkyle
kastnerkyle / top-k-top-p.py
Created May 3, 2019 13:58 — forked from thomwolf/top-k-top-p.py
Sample the next token from a probability distribution using top-k and/or nucleus (top-p) sampling
def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')):
""" Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
Args:
logits: logits distribution shape (..., vocabulary size)
top_k >0: keep only top k tokens with highest probability (top-k filtering).
top_p >0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
"""
top_k = min(top_k, logits.size(-1)) # Safety check
if top_k > 0:
# Remove all tokens with a probability less than the last token of the top-k
@kastnerkyle
kastnerkyle / Instantaneous Frequency and Phase Derivatives.ipynb
Created March 20, 2019 16:13
Instantaneous frequency and rainbowgrams with librosa.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// Uncompressed version of
// https://gist.github.com/munificent/b1bcd969063da3e6c298be070a22b604
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#include <stdbool.h> // 2008-2019
const int HEIGHT = 40;
const int WIDTH = 80;
@kastnerkyle
kastnerkyle / .gitignore
Created March 11, 2019 20:31 — forked from ctsrc/.gitignore
Random dungeon generator from https://news.ycombinator.com/item?id=19309378, deobfuscated, refactored and commented
/.idea/
/cmake-build-debug/
/dungeon
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kastnerkyle
kastnerkyle / install-cuda.sh
Created December 9, 2018 08:27 — forked from honnibal/install-cuda.sh
Provision GPU for Ubuntu 18.04
#!/usr/bin/env bash
# First download cudnn to a directory /tmp/binaries.
# The filename should be cudnn-9.2-linux-x64-v7.1.tgz
set -e
# Install driver
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
from z3 import *
# find the (distinct) integers in 0..9 that make this equation work:
#
# SEND
# + MORE
# ------
# MONEY
S = Int('S')
@kastnerkyle
kastnerkyle / memoise.py
Created August 9, 2018 10:14 — forked from dutc/memoise.py
How short & how complete can we write a memoising decorator? I think the below is more complete than most formulations (which don't cache independent of arg-binding.) I think it also cuts straight to the core of what memoisation means. Three obvious deficiencies: [1] What do we do about instance and class methods? These can be meaningfully memoi…
from sys import version_info
assert version_info.major == 3 and version_info.minor >= 3, \
'requires PEP 362; Python 3.3 or later; python.org/dev/peps/pep-0362/'
from inspect import signature
class memoise(dict):
def __init__(self, func):
self.func, self.signature = func, signature(func)
def __missing__(self, key):
args, kwargs = key
@kastnerkyle
kastnerkyle / download_haeckel.sh
Created July 30, 2018 01:59 — forked from genekogan/download_haeckel.sh
script to scrape scanned illustrations from Ernst Haeckel's book Kunstformen der Natur (Artforms of Nature)
for i in {1..100}; do
filepath=$(printf "http://caliban.mpipz.mpg.de/haeckel/kunstformen/Tafel_%03d_300.jpg" $i)
wget $filepath;
done
@kastnerkyle
kastnerkyle / Signal reconstruction from spectrograms.ipynb
Created May 31, 2018 18:17 — forked from carlthome/Signal reconstruction from spectrograms.ipynb
Try to recover audio from filtered magnitudes when phase information has been lost.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.