Ejemplo n.º 1
0
def validate():
    acc = []
    for (i, (x, y)) in enumerate(examples.get_validation_example()):
        if HYPERPARAMETERS["locally normalize"]:
            targety = N.array([y])
        else:
            targety = N.zeros(ODIM)
            targety[y] = 1.
        if HLAYERS == 2:
            o = graph.validatefn([x.data], targety, w1[x.indices], b1, wh, bh, w2, b2)
            (kl, softmax, argmax, prehidden1, prehidden2) = o
        else:
            o = graph.validatefn([x.data], targety, w1[x.indices], b1, w2, b2)
            (kl, softmax, argmax, prehidden) = o

        if argmax == y: acc.append(1.)
        else: acc.append(0.)

        if i < 5:
            if HLAYERS == 2:
                abs_prehidden(prehidden1, "Prehidden1")
                abs_prehidden(prehidden2, "Prehidden2")
            else:
                abs_prehidden(prehidden)       

    return N.mean(acc), N.std(acc)
Ejemplo n.º 2
0
def validate(cnt):
    import math
    logranks = []
    logging.info("BEGINNING VALIDATION AT TRAINING STEP %d" % cnt)
    logging.info(stats())
    i = 0
    for (i, ve) in enumerate(examples.get_validation_example()):
#        logging.info([wordmap.str(id) for id in ve])
        logranks.append(math.log(m.validate(ve)))
        if (i+1) % 10 == 0:
            logging.info("Training step %d, validating example %d, mean(logrank) = %.2f, stddev(logrank) = %.2f" % (cnt, i+1, numpy.mean(numpy.array(logranks)), numpy.std(numpy.array(logranks))))
            logging.info(stats())
    logging.info("FINAL VALIDATION AT TRAINING STEP %d: mean(logrank) = %.2f, stddev(logrank) = %.2f, cnt = %d" % (cnt, numpy.mean(numpy.array(logranks)), numpy.std(numpy.array(logranks)), i+1))
    logging.info(stats())
Ejemplo n.º 3
0
def validate(cnt):
    import math
    logranks = []
    logging.info("BEGINNING VALIDATION AT TRAINING STEP %d" % cnt)
    logging.info(stats())
    i = 0
    for (i, ve) in enumerate(examples.get_validation_example()):
#        logging.info([wordmap.str(id) for id in ve])
        logranks.append(math.log(m.validate(ve)))
        if (i+1) % 10 == 0:
            logging.info("Training step %d, validating example %d, mean(logrank) = %.2f, stddev(logrank) = %.2f" % (cnt, i+1, numpy.mean(numpy.array(logranks)), numpy.std(numpy.array(logranks))))
            logging.info(stats())
    logging.info("FINAL VALIDATION AT TRAINING STEP %d: mean(logrank) = %.2f, stddev(logrank) = %.2f, cnt = %d" % (cnt, numpy.mean(numpy.array(logranks)), numpy.std(numpy.array(logranks)), i+1))
    logging.info(stats())
Ejemplo n.º 4
0
def debug_prehidden_values(cnt, model):
    """
    Give debug output on pre-squash hidden values.
    """
    for (i, ve) in enumerate(examples.get_validation_example()):
        (score, prehidden) = model.verbose_predict(ve)
        abs_prehidden = numpy.abs(prehidden)
        med = numpy.median(abs_prehidden)
        abs_prehidden = abs_prehidden.tolist()
        assert len(abs_prehidden) == 1
        abs_prehidden = abs_prehidden[0]
        abs_prehidden.sort()
        abs_prehidden.reverse()
        logging.info("%s %s %s %s %s" % (cnt, "abs(pre-squash hidden) median =", med, "max =", abs_prehidden[:3]))
        if i+1 >= 3: break
Ejemplo n.º 5
0
def debug_prehidden_values(cnt, model):
    """
    Give debug output on pre-squash hidden values.
    """
    for (i, ve) in enumerate(examples.get_validation_example()):
        (score, prehidden) = model.verbose_predict(ve)
        abs_prehidden = numpy.abs(prehidden)
        med = numpy.median(abs_prehidden)
        abs_prehidden = abs_prehidden.tolist()
        assert len(abs_prehidden) == 1
        abs_prehidden = abs_prehidden[0]
        abs_prehidden.sort()
        abs_prehidden.reverse()
        logging.info("%s %s %s %s %s" %
                     (cnt, "abs(pre-squash hidden) median =", med, "max =",
                      abs_prehidden[:3]))
        if i + 1 >= 3: break
Ejemplo n.º 6
0
def validate():
    acc = []
    for (i, (x, y)) in enumerate(examples.get_validation_example()):
        if HLAYERS == 2:
            o = graph.validatefn(x, N.array([y]), w1, b1, wh, bh, w2, b2)
            (kl, softmax, argmax, prehidden1, prehidden2) = o
        else:
            o = graph.validatefn(x, N.array([y]), w1, b1, w2, b2)
            (kl, softmax, argmax, prehidden) = o

        if argmax == y: acc.append(1.)
        else: acc.append(0.)

        if i < 5:
            if HLAYERS == 2:
                abs_prehidden(prehidden1, "Prehidden1")
                abs_prehidden(prehidden2, "Prehidden2")
            else:
                abs_prehidden(prehidden)

    return N.mean(acc), N.std(acc)
Ejemplo n.º 7
0
def validate():
    acc = []
    for (i, (x, y)) in enumerate(examples.get_validation_example()):
        if HLAYERS == 2:
            o = graph.validatefn(x, N.array([y]), w1, b1, wh, bh, w2, b2)
            (kl, softmax, argmax, prehidden1, prehidden2) = o
        else:
            o = graph.validatefn(x, N.array([y]), w1, b1, w2, b2)
            (kl, softmax, argmax, prehidden) = o

        if argmax == y: acc.append(1.)
        else: acc.append(0.)

        if i < 5:
            if HLAYERS == 2:
                abs_prehidden(prehidden1, "Prehidden1")
                abs_prehidden(prehidden2, "Prehidden2")
            else:
                abs_prehidden(prehidden)       

    return N.mean(acc), N.std(acc)