This file contains 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 sys | |
if len(sys.argv) < 2: | |
print "Usage: %s <file-name>"%sys.argv[0] | |
exit(0) | |
fname = sys.argv[1] | |
import json | |
lookup = {'outputs':[], 'execution_count':None} |
This file contains 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 ctypes | |
# Path to location of libcudart | |
# Change the path to "cudart<x>_<ver>.dll" to use on Windows, where <x>={32|64} and <ver> is the CUDA version. | |
_CUDA = "/usr/local/cuda/lib/libcudart.dylib" | |
cuda = ctypes.cdll.LoadLibrary(_CUDA) | |
cuda.cudaMemGetInfo.restype = int | |
cuda.cudaMemGetInfo.argtypes = [ctypes.c_void_p, ctypes.c_void_p] |
This file contains 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
# variation to https://github.com/ryankiros/skip-thoughts/blob/master/decoding/search.py | |
def keras_rnn_predict(samples, empty=empty, rnn_model=model, maxlen=maxlen): | |
"""for every sample, calculate probability for every possible label | |
you need to supply your RNN model and maxlen - the length of sequences it can handle | |
""" | |
data = sequence.pad_sequences(samples, maxlen=maxlen, value=empty) | |
return rnn_model.predict(data, verbose=0) | |
def beamsearch(predict=keras_rnn_predict, |
This file contains 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 numpy as np | |
import h5py | |
import keras.backend as K | |
def str_shape(x): | |
return 'x'.join(map(str, x.shape)) | |
def load_weights(model, filepath, lookup={}, ignore=[], transform=None, verbose=True): | |
"""Modified version of keras load_weights that loads as much as it can. | |
Useful for transfer learning. |
This file contains 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 keras.layers.core import Lambda | |
class RemoveMask(Lambda): | |
def __init__(self): | |
super(RemoveMask, self).__init__((lambda x, mask: x)) | |
self.supports_masking = True | |
def compute_mask(self, input, input_mask=None): | |
return None |
This file contains 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 numpy as np | |
from keras.layers import GRU, initializations, K | |
from collections import OrderedDict | |
class GRULN(GRU): | |
'''Gated Recurrent Unit with Layer Normalization | |
Current impelemtation only works with consume_less = 'gpu' which is already | |
set. | |
# Arguments |
This file contains 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
0x4CDE69AE1A924010Ba33F2944A4bb6dfbFB64958 |