From e1673538607a7c8d784013b21b753f0c05c4cc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Simon?= Date: Tue, 21 Jul 2015 18:26:43 -0400 Subject: Genericize RNNs --- model/rnn_tgtcls.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 model/rnn_tgtcls.py (limited to 'model/rnn_tgtcls.py') diff --git a/model/rnn_tgtcls.py b/model/rnn_tgtcls.py new file mode 100644 index 0000000..0c0faf2 --- /dev/null +++ b/model/rnn_tgtcls.py @@ -0,0 +1,19 @@ +import numpy +import theano +from theano import tensor +from blocks.bricks.base import lazy +from blocks.bricks import Softmax + +from model.rnn import RNN, Stream + + +class Model(RNN): + @lazy() + def __init__(self, config, **kwargs): + super(Model, self).__init__(config, output_dim=config.tgtcls.shape[0], **kwargs) + self.classes = theano.shared(numpy.array(config.tgtcls, dtype=theano.config.floatX), name='classes') + self.softmax = Softmax() + self.children.append(self.softmax) + + def process_rto(self, rto): + return tensor.dot(self.softmax.apply(rto), self.classes) -- cgit v1.2.3