def setUp(self): x_shape = (self.batch_size, self.in_size) self.x = numpy.random.uniform(-1, 1, x_shape).astype(numpy.float32) self.t = numpy.random.randint(len(self.count), size=self.batch_size).astype(numpy.int32) self.link = links.BlackOut(self.in_size, self.count, self.n_samples) self.w = numpy.random.uniform(-1, 1, self.link.W.data.shape) self.link.W.data[:] = self.w
def __init__(self, vocab_size, embed_size, hidden_size, counts, sample_size=200): super(Decoder, self).__init__( ye=L.EmbedID(vocab_size, embed_size, ignore_label=-1), eh=L.Linear(embed_size, 4 * hidden_size), hh=L.Linear(hidden_size, 4 * hidden_size), wc=L.Linear(hidden_size, hidden_size), wh=L.Linear(hidden_size, hidden_size), fy=L.BlackOut(hidden_size, counts=counts, sample_size=sample_size), test_out=L.Linear(hidden_size, vocab_size), ) self.fy.W.data = self.test_out.W.data
def setUp(self): self._config_user = chainer.using_config('dtype', self.dtype) self._config_user.__enter__() x_shape = (self.batch_size, self.in_size) self.x = numpy.random.uniform(-1, 1, x_shape).astype(self.dtype) self.t = numpy.random.randint(len(self.count), size=self.batch_size).astype(numpy.int32) self.link = links.BlackOut(self.in_size, self.count, self.n_samples) self.w = numpy.random.uniform(-1, 1, self.link.W.data.shape) self.link.W.data[:] = self.w if self.dtype == numpy.float16: self.check_forward_options = {'atol': 5e-3} else: self.check_forward_options = {'atol': 1e-4}