Ejemplo n.º 1
0
    def test_vector_out(self):
        encdec = SimpleSeqEncDecAtt(inpvocsize=19, outvocsize=17, outconcat=False, decdim=110)
        encdata = np.random.randint(0, 19, (1, 5))
        decdata = np.random.randint(0, 17, (1, 5))
        pred = encdec.predict(encdata, decdata)
        self.assertEqual(pred.shape, (1, 5, 17))

        encdec = SimpleSeqEncDecAtt(inpvocsize=19, outvocsize=17, vecout=True, outconcat=False, decdim=110)
        pred = encdec.predict(encdata, decdata)
        print pred.shape
        self.assertEqual(pred.shape, (1, 5, 110))
Ejemplo n.º 2
0
    def do_test_shapes(self, bidir=False, sepatt=False, rnu=GRU):
        inpvocsize = 100
        outvocsize = 13
        inpembdim = 10
        outembdim = 7
        encdim = [26, 14]
        decdim = [21, 15]
        batsize = 11
        inpseqlen = 6
        outseqlen = 5

        if bidir:
            encdim = [e / 2 for e in encdim]

        m = SimpleSeqEncDecAtt(inpvocsize=inpvocsize,
                               inpembdim=inpembdim,
                               outvocsize=outvocsize,
                               outembdim=outembdim,
                               encdim=encdim,
                               decdim=decdim,
                               bidir=bidir,
                               statetrans=True,
                               attdist=LinearDistance(15, 14, 17),
                               sepatt=sepatt,
                               rnu=rnu)

        inpseq = np.random.randint(0, inpvocsize,
                                   (batsize, inpseqlen)).astype("int32")
        outseq = np.random.randint(0, outvocsize,
                                   (batsize, outseqlen)).astype("int32")

        predenco, enco, states = m.enc.predict(inpseq)
        self.assertEqual(
            predenco.shape,
            (batsize, encdim[-1] if not bidir else encdim[-1] * 2))
        if rnu == GRU:
            self.assertEqual(len(states), 2)
            for state, encdime in zip(states, encdim):
                self.assertEqual(state.shape,
                                 (batsize, inpseqlen,
                                  encdime if not bidir else encdime * 2))
        elif rnu == LSTM:
            self.assertEqual(len(states), 4)
            for state, encdime in zip(
                    states, [encdim[0], encdim[0], encdim[1], encdim[1]]):
                self.assertEqual(state.shape,
                                 (batsize, inpseqlen,
                                  encdime if not bidir else encdime * 2))

        if sepatt:
            self.assertEqual(enco.shape,
                             (batsize, inpseqlen, 2,
                              encdim[-1] if not bidir else encdim[-1] * 2))

        pred = m.predict(inpseq, outseq)
        self.assertEqual(pred.shape, (batsize, outseqlen, outvocsize))

        _, outvar = m.autobuild(inpseq, outseq)
        for p in sorted(outvar[0].allparams, key=lambda x: str(x)):
            print p
Ejemplo n.º 3
0
    def do_test_shapes(self, bidir=False):
        inpvocsize = 100
        outvocsize = 13
        inpembdim = 10
        outembdim = 5
        encdim = 9
        decdim = 7
        attdim = 8
        batsize = 11
        inpseqlen = 7
        outseqlen = 5

        m = SimpleSeqEncDecAtt(inpvocsize=inpvocsize,
                               inpembdim=inpembdim,
                               outvocsize=outvocsize,
                               outembdim=outembdim,
                               encdim=encdim,
                               decdim=decdim,
                               attdim=attdim,
                               bidir=bidir)

        inpseq = np.random.randint(0, inpvocsize,
                                   (batsize, inpseqlen)).astype("int32")
        outseq = np.random.randint(0, outvocsize,
                                   (batsize, outseqlen)).astype("int32")

        predenco, _, _ = m.enc.predict(inpseq)
        self.assertEqual(predenco.shape,
                         (batsize, encdim if not bidir else encdim * 2))

        pred = m.predict(inpseq, outseq)
        self.assertEqual(pred.shape, (batsize, outseqlen, outvocsize))
Ejemplo n.º 4
0
    def do_test_shapes(self, bidir=False):
        inpvocsize = 100
        outvocsize = 13
        inpembdim = 10
        outembdim = 5
        encdim = 9
        decdim = 7
        attdim = 8
        batsize = 11
        inpseqlen = 7
        outseqlen = 5

        m = SimpleSeqEncDecAtt(inpvocsize=inpvocsize,
                               inpembdim=inpembdim,
                               outvocsize=outvocsize,
                               outembdim=outembdim,
                               encdim=encdim,
                               decdim=decdim,
                               attdim=attdim,
                               bidir=bidir)

        inpseq = np.random.randint(0, inpvocsize, (batsize, inpseqlen)).astype("int32")
        outseq = np.random.randint(0, outvocsize, (batsize, outseqlen)).astype("int32")

        predenco, _, _ = m.enc.predict(inpseq)
        self.assertEqual(predenco.shape, (batsize, encdim if not bidir else encdim*2))

        pred = m.predict(inpseq, outseq)
        self.assertEqual(pred.shape, (batsize, outseqlen, outvocsize))
    def test_vector_out(self):
        encdec = SimpleSeqEncDecAtt(inpvocsize=19,
                                    outvocsize=17,
                                    outconcat=False,
                                    decdim=110)
        encdata = np.random.randint(0, 19, (1, 5))
        decdata = np.random.randint(0, 17, (1, 5))
        pred = encdec.predict(encdata, decdata)
        self.assertEqual(pred.shape, (1, 5, 17))

        encdec = SimpleSeqEncDecAtt(inpvocsize=19,
                                    outvocsize=17,
                                    vecout=True,
                                    outconcat=False,
                                    decdim=110)
        pred = encdec.predict(encdata, decdata)
        print pred.shape
        self.assertEqual(pred.shape, (1, 5, 110))