Skip to content

Instantly share code, notes, and snippets.

View rizar's full-sized avatar

Dzmitry Bahdanau rizar

  • ServiceNow Research
View GitHub Profile
@rizar
rizar / main.py
Last active August 29, 2015 14:07
How to handle undefined parameteres without decorators
class UnDef():
pass
UNDEF = UnDef()
class Block(object):
def __getattribute__(self, name):
value = object.__getattribute__(self, name)
if value == UNDEF:
@rizar
rizar / MTsketch.py
Last active August 29, 2015 14:07
Machine Translation in the Future
# INTRODUCTION
# ------------
#
# Bart's logistic regression oneliner has served us well
# forcing us to think how to make the framework
# suitable for quick-and-dirty experimentation with small
# standard models. It did not force us to think about
# scalability and flexibility necessary for big
# experiments with big models.
#
@rizar
rizar / scan_updates.py
Created October 22, 2014 20:31
Theano Scan Updates
import theano
from theano.tensor.shared_randomstreams import RandomStreams
r = RandomStreams(1)
y, u = theano.scan(lambda : r.binomial(size=(2, 2)), n_steps=3)
f = theano.function([], [y])
# It still gives me three different sequence of random matrices!
print f()
............/home/rizar/Dist/theano/theano/scan_module/scan_perform_ext.py:133: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility
from scan_perform.scan_perform import *
...ERROR (theano.gof.opt): SeqOptimizer apply <theano.gof.opt.EquilibriumOptimizer object at 0x4ac9c50>
ERROR (theano.gof.opt): Traceback:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "/home/rizar/Dist/theano/theano/gof/opt.py", line 195, in apply
sub_prof = optimizer.optimize(fgraph)
File "/home/rizar/Dist/theano/theano/gof/opt.py", line 81, in optimize
ret = self.apply(fgraph, *args, **kwargs)
File "/home/rizar/Dist/theano/theano/gof/opt.py", line 1693, in apply
import numpy
import theano
from theano import tensor
from theano.printing import debugprint
floatX = theano.config.floatX
foo_a, foo_x, r = 3 * [None]
def foo(x, a):
@rizar
rizar / data_streams.py
Last active August 29, 2015 14:11
Data Streams
class Data(object):
"""Super abstract class for all data sources.
So far does not have neither methods nor attributes,
but perhaps it can provide some sort-of signature,
e.g. channel names.
"""
pass
@rizar
rizar / recurrent_with_fork.py
Created June 7, 2015 16:37
Recurrent with fork
class RecurrentWithFork(Initializable):
@lazy(allocation=['input_dim'])
def __init__(self, recurrent, input_dim, **kwargs):
super(RecurrentWithFork, self).__init__(**kwargs)
self.recurrent = recurrent
self.input_dim = input_dim
self.fork = Fork(
[name for name in self.recurrent.sequences
if name != 'mask'],
@rizar
rizar / gist:183620f9cfec98f2acd4
Created June 17, 2015 15:42
Deep BiRNN for Blocks
# This to illustrate the idea how deep BiRNN will be implemented in Blocks.
class RecurrentWithFork(Initializable):
@lazy(allocation=['input_dim'])
def __init__(self, recurrent, input_dim, **kwargs):
super(RecurrentWithFork, self).__init__(**kwargs)
self.recurrent = recurrent
self.input_dim = input_dim
self.fork = Fork(
@rizar
rizar / strip.py
Last active September 10, 2015 21:52
Strip computation graph off annotations
seen = set()
def strip(obj):
if id(obj) in seen:
return
seen.add(id(obj))
if isinstance(obj, theano.Variable):
obj.tag.annotations = []
obj.tag.roles = []
if isinstance(obj, (list, tuple, set)):
for el in obj:
@rizar
rizar / lstm.diff
Created April 1, 2016 20:54
Patch required to make reverse_words work with LSTM
diff --git a/reverse_words/__init__.py b/reverse_words/__init__.py
index b649ab5..ac296e7 100644
--- a/reverse_words/__init__.py
+++ b/reverse_words/__init__.py
@@ -14,7 +14,7 @@ from theano import tensor
from blocks.bricks import Tanh, Initializable
from blocks.bricks.base import application
from blocks.bricks.lookup import LookupTable
-from blocks.bricks.recurrent import SimpleRecurrent, Bidirectional
+from blocks.bricks.recurrent import SimpleRecurrent, LSTM, Bidirectional