def apply(self, sentences, init_hid=None):
"""
Parameters
----------
sentences: (length, batch, featuresdim)
Returns
-------
hs: (n_blocks, batch, hid_size)
"""
if sentences.ndim == 3:
batch_size = sentences.shape[1]
n_steps = sentences.shape[0]
else:
raise NotImplementedError
if init_hid is None:
init_hid = T.unbroadcast(T.alloc(numpy.float32(0.), batch_size, self.hid_size))
rval, updates = theano.scan(self._step_forward,
sequences=[sentences],
outputs_info=[init_hid],
n_steps=n_steps
)
self.hs = rval
return self.hs
评论列表
文章目录