Exemplo n.º 1
0
        self.O = param((dim, self.outdim), lrmul=1.).glorotuniform()

    def apply(self, inptensor):
        emb = self.W(inptensor)
        out = T.dot(emb, self.O)
        out.output_as("out")
        probs = Softmax()(out)
        return probs


def run(epochs=1, dim=10, vocabsize=2000, lr=0.02, numbats=100):
    lr *= numbats
    data = np.arange(0, vocabsize).astype("int32")
    ae = Dummy(indim=vocabsize, dim=dim)
    ae = ae.train([data], data).adadelta(lr=lr).dlr_thresh().cross_entropy()\
            .split_validate(5, random=True).cross_entropy().accuracy().autosave\
        .train(numbats=numbats, epochs=epochs)

    pdata = range(100)
    pembs = ae.W.predict(pdata)
    #print np.linalg.norm(pembs, axis=1)
    pred = ae.predict(pdata)
    print pred.shape
    #print np.argmax(pred, axis=1)
    #print err, verr
    return pred


if __name__ == "__main__":
    run(**argparsify(run))
Exemplo n.º 2
0
        probs = Softmax()(out)
        return probs


def run(
        epochs=1,
        dim=10,
        vocabsize=2000,
        lr=0.02,
        numbats=100
    ):
    lr *= numbats
    data = np.arange(0, vocabsize).astype("int32")
    ae = Dummy(indim=vocabsize, dim=dim)
    ae = ae.train([data], data).adadelta(lr=lr).dlr_thresh().cross_entropy()\
            .split_validate(5, random=True).cross_entropy().accuracy().autosave\
        .train(numbats=numbats, epochs=epochs)

    pdata = range(100)
    pembs = ae.W.predict(pdata)
    #print np.linalg.norm(pembs, axis=1)
    pred = ae.predict(pdata)
    #print pred.shape
    #print np.argmax(pred, axis=1)
    #print err, verr
    return pred


if __name__ == "__main__":
    run(**argparsify(run))
Exemplo n.º 3
0
 def test_argparsify(self):
     def testf(a=1, b="str"):
         pass
     self.assertEqual(argparsify(testf, test="-a 1"), {"a": 1})
Exemplo n.º 4
0
    def test_argparsify(self):
        def testf(a=1, b="str"):
            pass

        self.assertEqual(argparsify(testf, test="-a 1"), {"a": 1})