This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# | |
# @author Jonathan Raiman | |
# @date 9th October 2014 | |
# | |
# Messing around with Stanford's GloVe words | |
# Download them [here](http://www-nlp.stanford.edu/projects/glove/) | |
import gzip, numpy as np, io |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import theano, theano.tensor as T, numpy as np | |
def _outer_substract(x, y): | |
x = x.dimshuffle(0, 1, 'x') | |
x = T.addbroadcast(x, 2) | |
return (x - y.T).T | |
def _gaussian_kernel(x, y, beta = 0.1): | |
K = _outer_substract(x,y) | |
return T.exp( -beta * K.norm(L=2,axis=1)) | |
x = T.matrix() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%cython | |
import cython | |
import numpy as np | |
cimport numpy as np | |
from libc.math cimport exp | |
from libc.string cimport memset | |
from cpython cimport PyCapsule_GetPointer # PyCObject_AsVoidPtr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%cython | |
import cython | |
from cython cimport view | |
import numpy as np | |
cimport numpy as np | |
from cpython cimport PyCapsule_GetPointer # PyCObject_AsVoidPtr | |
from scipy.linalg.blas import fblas | |
REAL = np.float32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to get gemm to work in Cython | |
# 1. suppose your data is Fortran contiguous (really ?) | |
# then blas supports this out of the box: | |
%%cython | |
cimport numpy as np | |
import numpy as np | |
from cpython cimport PyCapsule_GetPointer # PyCObject_AsVoidPtr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from libc.stdlib cimport malloc, free, realloc | |
cdef struct Chair: | |
int size | |
cdef class Bench: | |
cdef Chair* chairs | |
cdef readonly int num_chairs | |
property chairs: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import pickle | |
protocol = 0 | |
sqlite3.register_converter("pickle", pickle.loads) | |
sqlite3.register_adapter(list, pickle.dumps) | |
sqlite3.register_adapter(set, pickle.dumps) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import theano, theano.tensor as T, numpy as np | |
import theano_lstm | |
import os | |
from collections import Counter | |
to_softmax = lambda x: T.nnet.softmax(x)[0] if x.ndim == 1 else T.nnet.softmax(x.T).T | |
class LatticeModel(object): | |
def __init__(self, | |
word_size, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# stop script on error and print it | |
set -e | |
# inform me of undefined variables | |
set -u | |
# handle cascading failures well | |
set -o pipefail | |
# install homebrew |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DALI_MATH_MSHADOW_EIGEN_DOT_H | |
#define DALI_MATH_MSHADOW_EIGEN_DOT_H | |
#if MSHADOW_USE_EIGEN_DOT | |
#include <Eigen/Eigen> | |
#include <mshadow/tensor.h> | |
#include <cblas.h> | |
// Eigen Backend for Dot-Product in Mshadow | |
// Causes Adagrad to be slower. |
OlderNewer