Skip to content

Instantly share code, notes, and snippets.

View hans's full-sized avatar

Jon Gauthier hans

View GitHub Profile
@hans
hans / embed_skim_notes.sh
Created May 1, 2018 17:23
Embed Skim notes in a collection of PDFs
#!/usr/local/bin/zsh
# In a PDF library with associated Skim notes, automatically embed all
# skim notes in the PDF files.
# I used this to help transition from an OS X + Skim reading environment
# to a Linux reading environment.
# WARNING: This script deletes the Skim files after embedding their contents
# in the PDFs. Make sure you back up your library before using.
@hans
hans / oms_vm.sh
Last active February 8, 2018 18:34
export VAGRANT_HOME=/om2/user/$USER/vagrant
dir=/om2/user/$USER/vms/ibex
mkdir -p $VAGRANT_HOME || exit 1
mkdir -p $dir || exit 1
cd $dir
# Set up an Ubuntu 16 VM managed by Vagrant.
vagrant init ubuntu/xenial64
@hans
hans / classify.awk
Last active January 21, 2018 16:14
Convert CHILDES XML files to CONLL-U style dependency treebank files.
BEGIN {
c["little"]="size";
c["big"]="size";
c["white"]="color";
c["green"]="color";
c["blue"]="color";
c["red"]="color";
c["good"]="char";
c["bad"]="char";
c["first"]="ord";
@hans
hans / suncg.patch
Last active November 3, 2017 14:26
diff -ruw ./gaps/Makefile ../../SUNCGtoolbox-master/gaps/Makefile
--- ./gaps/Makefile 2017-10-01 23:23:17.000000000 +0000
+++ ../../SUNCGtoolbox-master/gaps/Makefile 2017-11-03 14:25:28.760111809 +0000
@@ -31,7 +31,7 @@
target:
cd pkgs; $(MAKE) $(TARGET)
cd apps; $(MAKE) $(TARGET)
- cd vc; $(MAKE) $(TARGET)
+ # cd vc; $(MAKE) $(TARGET)
# cd docs; $(MAKE) $(TARGET)
@hans
hans / gpu_row_switch.py
Last active December 23, 2015 05:41
Theano implementation of a GPU kernel for row-wise switch operation
import theano
from theano import gof
from theano import tensor as T
from theano.sandbox.cuda import GpuOp
from theano.sandbox.cuda.basic_ops import (CudaNdarrayType, GpuFromHost,
HostFromGpu,
as_cuda_ndarray_variable)
from theano.tensor.opt import register_specialize_device
from collections import OrderedDict
import numpy as np
import theano
from theano import tensor as T
class MyAdvancedSetSubtensor1(T.subtensor.AdvancedIncSubtensor1):
def get_inplace(self):
@hans
hans / stack.py
Created November 26, 2015 04:34
Gradient-friendly stack test
from collections import namedtuple
import unittest
Compose = namedtuple("Compose", ["a", "b"])
class Stack(object):
def __init__(self, compose_fn, n):
@hans
hans / cudnn_softmax.cu
Last active August 2, 2021 00:23
Example of CuDNN softmax usage
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <cudnn.h>
/**
* Verified correctness with cuDNN 6.5-R1.
*
* Author: Jon Gauthier <[email protected]>
@hans
hans / scan_variable.py
Created March 21, 2015 16:24
Example using theano.scan to output a variable-length sequence. (Useful for e.g. generator RNNs.)
import numpy as np
import theano
import theano.tensor as T
x = T.bscalar('x')
def scan_f(x):
# Second argument "until" establishes a stop condition
@hans
hans / average_embeddings.py
Last active March 26, 2018 18:50
Generate embeddings for rare words in a document by averaging the embeddings of associated context words. Find nearest neighbors of these embeddings to evaluate their quality.
from collections import Counter, defaultdict
import itertools
import os
import random
import re
import numpy as np
EMBEDDING_FILE = "/u/nlp/data/depparser/nn/data/embeddings/en-cw.txt"
EMBEDDING_SERIALIZED = "embeddings.npz"