Skip to content

Instantly share code, notes, and snippets.

View MInner's full-sized avatar

Ben Usman MInner

View GitHub Profile
@MInner
MInner / theano_optimization_snippet.ipynb
Last active November 7, 2015 02:13
(Example) Optimization Using Theano
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def load_experiment_backup(model_name):
filename = 'h_backup/%s.pickle' % model_name
if os.path.isfile(filename):
with open(filename, 'rb') as handle:
return pickle.load(handle)
else:
return Trials()
def update_experiment_backup(trials, model_name):
with open('h_backup/%s.pickle' % model_name, 'wb') as f:
import tensorflow as tf
import numpy as np
class tnpg:
def __init__(self, tf_arr):
self.arr = tf_arr
def __getitem__(self, idx):
if any([type(x) not in [slice, tf.python.framework.ops.Tensor, list] for x in idx]):
raise ValueError("Unsupported type (not slice, tensor or list)! "
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MInner
MInner / restore_using_variable_scope.py
Created April 4, 2017 19:01
One way of restoring weights when computation graph structure has changed
# example code for EC500 K1 / CS591 S2 Deep Learning (Spring 2017)
import tensorflow as tf
import numpy as np
def main_save():
with tf.Graph().as_default() as g:
with tf.variable_scope('to_save'):
a = tf.get_variable('a_name', [100, 100])
backtick 0 0 0 whoami
caption always "%{-b ..}%-w%{+b ..}[[%n%f*%t]]%{-}%+w %= %0`@%H | %l"
bind ` focus prev
@MInner
MInner / top_k_seq2seq.py
Last active October 25, 2017 02:46
This snipped extracts top k beams from the beam search output of github.com/google/seq2seq.
# based on https://github.com/google/seq2seq/blob/master/bin/tools/generate_beam_viz.py
# extracts probabilities and sequences from .npz file generated during beam search.
# and pickles a list of the length n_samples that has beam_width most probable tuples
# (path, logprob, prob)
# where probs are scaled to 1.
import numpy as np
import networkx as nx
import pickle
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.