Esempio n. 1
0
    def setUp(self):
        tree = ((0, 1), ((2, 3), 4))
        self.link = links.BinaryHierarchicalSoftmax(3, tree)
        self.link.cleargrads()
        self.x = numpy.random.uniform(-1, 1, (2, 3)).astype(numpy.float32)
        self.t = numpy.array([0, 2]).astype(numpy.int32)
        self.gy = numpy.random.uniform(-1, 1, ()).astype(numpy.float32)

        self.W = self.link.W.data.copy()
Esempio n. 2
0
 def __init__(self, n_vocab, n_units, tree, ratio=1., train=True):
     super(HSMmodel, self).__init__(
         embed=L.EmbedID(n_vocab, n_units),
         l1=L.LSTM(n_units, n_units),
         l2=L.LSTM(n_units, n_units),
         l3=L.Linear(n_units, n_units),
         # lossfun=SoftmaxCrossEntropyLoss(n_units, n_vocab),
         lossfun=L.BinaryHierarchicalSoftmax(n_units, tree),
     )
     self.train = train
     self.ratio = 1. - ratio
     self.y = None
     self.loss = None
     self.accuracy = None
     self.compute_accuracy = True
Esempio n. 3
0
 def __init__(self, params):
     self.__dict__.update(params)
     super(GRU_Baseline, self).__init__(
         embed=L.EmbedID(self.n_vocab + 3, self.word_dim),
         gru=L.GRU(n_units=self.n_units, n_inputs=self.word_dim),
         #      l2v = L.Linear(
         #        in_size = self.n_units,
         #        out_size = self.n_vocab + 2
         #      )
         #      blackout = L.BlackOut(
         #        in_size = self.n_units,
         #        counts = self.vocab_counts,
         #        sample_size = self.blackout_sample_size
         #      )
         #      bottleneck = L.Linear(
         #        in_size = self.n_units,
         #        out_size = 128
         #      ),
         bh_softmax=L.BinaryHierarchicalSoftmax(in_size=self.n_units,
                                                tree=self.huffman_tree))
Esempio n. 4
0
    def setUp(self):
        self._config_user = chainer.using_config('dtype', self.dtype)
        self._config_user.__enter__()

        tree = ((0, 1), ((2, 3), 4))
        self.link = links.BinaryHierarchicalSoftmax(3, tree)
        self.link.cleargrads()
        self.x = numpy.random.uniform(-1, 1, (2, 3)).astype(self.dtype)
        self.t = numpy.array([0, 2]).astype(numpy.int32)
        self.gy = numpy.random.uniform(-1, 1, ()).astype(self.dtype)

        self.W = self.link.W.data.copy()

        if self.dtype == numpy.float16:
            self.check_sum_options = {'delta': 1e-3}
            self.test_forward_options = {'atol': 0.005}
            self.check_backward_options = {'dtype': numpy.float64}
        else:
            self.check_sum_options = {'delta': 1e-5}
            self.test_forward_options = {}
            self.check_backward_options = {}