Skip to content

Instantly share code, notes, and snippets.

View honnibal's full-sized avatar

Matthew Honnibal honnibal

View GitHub Profile
@honnibal
honnibal / theano_mlp_small.py
Last active March 1, 2023 15:10
Stripped-down example of Multi-layer Perceptron MLP in Theano
"""A stripped-down MLP example, using Theano.
Based on the tutorial here: http://deeplearning.net/tutorial/mlp.html
This example trims away some complexities, and makes it easier to see how Theano works.
Design changes:
* Model compiled in a distinct function, so that symbolic variables are not in run-time scope.
* No classes. Network shown by chained function calls.
@honnibal
honnibal / prodigy_srs.py
Created April 22, 2019 10:33
Script to jury-rig a little spaced-repeition system out of the Prodigy annotation tool
"""See https://twitter.com/honnibal/status/1120020992636661767 """
import time
import srsly
from prodigy import recipe
from prodigy.components.db import connect
from prodigy.util import INPUT_HASH_ATTR, set_hashes
from prodigy.components.filters import filter_duplicates
def get_rank_priority(data):
@honnibal
honnibal / install-cuda.sh
Created December 9, 2018 08:15
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
@honnibal
honnibal / dynamic_params.py
Last active June 29, 2017 09:30
Cycle hyper parameter
def cycle_hyper_param(low, high):
'''Dynamically oscillate a hyper-parameter between two values.
Uses the loss momentum to adjust the rate of change. The idea is
that the value should move through regions where the loss is flat
faster, and linger in values where the loss improves.
'''
inc = 0.0001
trend = 0.
prev = 0.
@honnibal
honnibal / gist:1231964e784ab9acb65d
Last active November 18, 2016 06:53
Example of parsing Reddit comment dumps with spaCy: http://spacy.io/
from __future__ import unicode_literals
from __future__ import print_function
import sys
import plac
import bz2
import ujson
import spacy.en
def main(input_loc):
#!/usr/bin/env bash
HERE=`pwd`
cd /tmp
wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz /tmp
tar -zxvf Python-2.7.5.tgz
cd Python-2.7.5
mkdir $HERE/.python
./configure --prefix=$HERE/.python
http://s000.tinyupload.com/index.php?file_id=07575878755298799648
# Simple sentiment analysis with lots and lots of problems. For answer to Quora thread:
# https://www.quora.com/Would-it-be-possible-for-an-undergraduate-like-me-to-create-a-sentiment-analysis-program
import sys
from collections import counter
with open(sys.argv[1]) as file_:
positive_text = file_.read()
with open(sys.argv[2]) as file_:
negative_text = file_.read()
@honnibal
honnibal / mc.pyx
Last active January 28, 2016 22:54
Monte carlo simulation, re /r/python thread on numba, cython, etc
# cython: infer_types=True
# cython: boundscheck=False
# cython: cdvision=True
# distutils: compile_options = ["-O2", "-fopenmp", "-march=native"]
# distutils: link_options = ["-fopenmp"]
cimport cython
from numpy import random as rng
import numpy as np
import numpy.random
@honnibal
honnibal / sort_like_color.py
Last active September 27, 2015 09:48
Find words that might be colors, using word vectors.
from __future__ import unicode_literals
from __future__ import print_function
import plac
import spacy.en
def main(vectors_loc=None):
nlp = spacy.en.English()