Пример #1
0
 def test_recappl(self):
     batsize = 100
     self.dims = [50, 20, 30, 40]
     recstack = RecStack(*[GRU(dim=self.dims[i], innerdim=self.dims[i+1]) for i in range(len(self.dims)-1)])
     mu = RecPredictor(recstack)
     for i in range(3):
         inpval = np.random.random((batsize, 50)).astype("float32")
         outpvals = mu.feed(inpval)
         self.assertEqual(outpvals.shape, (batsize, self.dims[-1]))
Пример #2
0
 def test_recappl_shapes_model_user(self):
     batsize = 100
     model = SimpleSeqTransDec(indim=200, outdim=50, inpembdim=20, outembdim=20, innerdim=[40, 30])
     mu = RecPredictor(model)
     inpval2 = np.random.randint(0, 50, (batsize,)).astype("int32")
     for i in range(5):
         inpval = np.random.randint(0, 200, (batsize,)).astype("int32")
         outpval = mu.feed(inpval, inpval2)
         inpval2 = np.argmax(outpval, axis=1).astype("int32")
         self.assertEqual(outpval.shape, (batsize, 50))
Пример #3
0
 def test_recappl(self):
     batsize = 100
     self.dims = [50, 20, 30, 40]
     recstack = RecStack(*[
         GRU(dim=self.dims[i], innerdim=self.dims[i + 1])
         for i in range(len(self.dims) - 1)
     ])
     mu = RecPredictor(recstack)
     for i in range(3):
         inpval = np.random.random((batsize, 50)).astype("float32")
         outpvals = mu.feed(inpval)
         self.assertEqual(outpvals.shape, (batsize, self.dims[-1]))
Пример #4
0
 def test_recappl_shapes_model_user(self):
     batsize = 100
     model = SimpleSeqTransDec(indim=200,
                               outdim=50,
                               inpembdim=20,
                               outembdim=20,
                               innerdim=[40, 30])
     mu = RecPredictor(model)
     inpval2 = np.random.randint(0, 50, (batsize, )).astype("int32")
     for i in range(5):
         inpval = np.random.randint(0, 200, (batsize, )).astype("int32")
         outpval = mu.feed(inpval, inpval2)
         inpval2 = np.argmax(outpval, axis=1).astype("int32")
         self.assertEqual(outpval.shape, (batsize, 50))
Пример #5
0
 def __init__(self, model, beamsize=1, *buildargs, **kw):
     super(Searcher, self).__init__(**kw)
     self.beamsize = beamsize
     self.model = model
     self.mu = RecPredictor(model, *buildargs)