Skip to content

Instantly share code, notes, and snippets.

View justheuristic's full-sized avatar
💭
on github.com/learning-at-home

justheuristic justheuristic

💭
on github.com/learning-at-home
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@justheuristic
justheuristic / gumbel_softmax.py
Created June 2, 2017 17:21
Mixture autoencoder with gumbel-softmax
# -*- coding: utf-8 -*-
"""
a bunch of lasagne code implementing gumbel softmax
https://arxiv.org/abs/1611.01144
"""
import numpy as np
import theano
import theano.tensor as T
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
from lasagne.random import get_rng
"""symbolic helper functions"""
import theano
import theano.tensor as T
import lasagne
from lasagne.layers import *
import numpy as np
def get_mask(tokens,pad_ix=-1):
assert tokens.ndim==2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lru_cache()
def infer_batch_axes(model,
get_dummy_input=lambda bsize: {'inp': tf.ones([bsize, 3], dtype='int32'),
'inp_len': tf.constant([3]*bsize, dtype='int32')},
check_at=(3, 5, 7),
sess=None, **flags):
"""
This function attempts to figure out batch dimensions by seeing what axes change on different batch sizes.
It stands as a monument of hatred to a person who thought that time-major axes order in tensorflow RNN is cool.
:param model: TranslateModel instance to figure out batch dimensions for.