Beispiel #1
0
def main():
    args = get_args()
    setup_logger(args)

    dset = Dset(**args)
    feat = featchar.Feat(args['feat'])
    feat.fit(dset)

    batcher = Batcher(args['n_batch'], feat)
    reporter = Reporter(dset, feat)

    validator = Validator(dset, batcher, reporter)

    RNN = RDNN_Dummy if args['rnn'] == 'dummy' else RDNN
    rdnn = RNN(feat.NC, feat.NF, args)
    if not args['load'] == '':
        dat = np.load(args['load'])
        dat_args = dat['argsd'].tolist()
        rnn_param_values = dat['rnn_param_values']
        params = lasagne.layers.get_all_params(rdnn.layers[-1])
        lasagne.layers.set_all_param_values(rdnn.layers[-1],
                rnn_param_values[:len(params)])
        logger = logging.getLogger()
        logger.info('Parameters loaded')


    validator.validate(rdnn, args)
Beispiel #2
0
def main():
    args = get_args()
    setup_logger(args)

    logging.info('loading params')
    dat = np.load(args['model_file'])
    dat_args = dat['argsd'].tolist()
    rnn_param_values = dat['rnn_param_values'].tolist()
    logging.info('params loaded')
    dat_args['fepoch'] = args['fepoch'] # TODO
    dat_args['save'] = args['save'] # TODO

    for k,v in sorted(dat_args.iteritems()):
        logging.info('{}:\t{}'.format(k,v))


    dset = Dset(**args)
    feat = featchar.Feat(dat_args['feat'])
    feat.fit(dset, xdsets=[Dset(dname) for dname in dat_args['charset']])

    batcher = Batcher(dat_args['n_batch'], feat)
    reporter = Reporter(dset, feat)

    validator = Validator(dset, batcher, reporter)

    rdnn = RDNN(feat.NC, feat.NF, dat_args)

    params = lasagne.layers.get_all_params(rdnn.layers[-1])
    lasagne.layers.set_all_param_values(rdnn.layers[-1], rnn_param_values[:len(params)])

    validator.validate(rdnn, dat_args)
Beispiel #3
0
    def __init__(self, model_file):
        dat = np.load(model_file)
        args = dat['argsd'].tolist()
        rnn_param_values = dat['rnn_param_values'].tolist()

        trn, dev, tst = get_sents(args['lang'])

        repclass = getattr(rep, 'Rep' + args['rep'])
        repobj = repclass()
        for d in (trn, dev, tst):
            for sent in d:
                sent.update({
                    'cseq': repobj.get_cseq(sent),
                    'wiseq': repobj.get_wiseq(sent),
                    'tseq': repobj.get_tseq(sent)
                })

        trn = sorted(trn, key=lambda sent: len(sent['cseq']))
        dev = sorted(dev, key=lambda sent: len(sent['cseq']))
        tst = sorted(tst, key=lambda sent: len(sent['cseq']))

        self.feat = featchar.Feat(args['feat'])
        self.feat.fit(trn, dev, tst)

        self.vdecoder = decoder.ViterbiDecoder(trn, self.feat)

        batcher = Batcher(args['n_batch'], self.feat)  # batch size 1
        devdat = batcher.get_batches(dev)
        tstdat = batcher.get_batches(tst)

        rdnn = RNN(self.feat.NC, self.feat.NF, args)
        cost, dev_predictions = rdnn.predict(devdat)
        cost, tst_predictions = rdnn.predict(tstdat)

        self.predictions = {}
        self.predictions['dev'] = dev_predictions
        self.predictions['tst'] = tst_predictions

        self.dset = {}
        self.dset['dev'] = dev
        self.dset['tst'] = tst
        self.repobj = repobj

        self.reporter = exper.Reporter(self.feat, rep.get_ts_bio)

        print rdnn.l_soft_out.get_params()
        print rdnn.blayers[0][0].get_params()
        params = lasagne.layers.get_all_param_values(rdnn.layers[-1])
        print map(np.shape, params)
        lasagne.layers.set_all_param_values(rdnn.layers[-1],
                                            rnn_param_values[:len(params)])

        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        shandler = logging.StreamHandler()
        shandler.setLevel(logging.INFO)
        logger.addHandler(shandler)

        validator = Validator(trn, dev, tst, batcher, self.reporter)
        validator.validate(rdnn, args, self.vdecoder)
Beispiel #4
0
def main():
    from utils import get_sents
    from dataset import Dset
    import featchar, rep

    trn, dev, tst = get_sents('toy')
    dset = Dset('toy')

    r = rep.Repstd()

    for sent in trn:
        sent.update({
            'cseq': r.get_cseq(sent),
            'wiseq': r.get_wiseq(sent),
            'tseq': r.get_tseq(sent)
        })
    r.pprint(trn[0])
    print
    r.pprint(trn[1])

    print rep.get_ts_bio(trn[0]['wiseq'], trn[0]['tseq'])

    feat = featchar.Feat('basic')
    feat.fit(dset)

    vdecoder = ViterbiDecoder(trn, feat)
    vdecoder.pprint()
    sent = trn[0]
    vdecoder.decode(sent, randlogprob(sent, feat.NC), debug=True)
    """
Beispiel #5
0
def main(args, rnn_param_values):
    # args = get_args()
    setup_logger(args)

    try:
        if args['seed']:
            rng = np.random.RandomState(args['seed'])
            lasagne.random.set_rng(rng)
        dset = Dset(**args)
        feat = featchar.Feat(args['feat'])
        feat.fit(dset, xdsets=[Dset(dname) for dname in args['charset']])

        batcher = Batcher(args['n_batch'], feat)
        reporter = Reporter(dset, feat)

        validator = Validator(dset, batcher, reporter)

        RNN = RDNN_Dummy if args['rnn'] == 'dummy' else RDNN
        rdnn = RNN(feat.NC, feat.NF, args)
        rdnn.set_param_values(rnn_param_values)

        validator.validate(rdnn, args)
    except Exception as e:
        print e
        logging.exception('an error occured.')
Beispiel #6
0
def main():
    args = get_args()
    setup_logger(args)

    dset = Dset(**args)
    feat = featchar.Feat(args['feat'])
    feat.fit(dset)

    batcher = Batcher(args['n_batch'], feat)
    reporter = Reporter(dset, feat)

    validator = Validator(dset, batcher, reporter)

    RNN = RDNN_Dummy if args['rnn'] == 'dummy' else RDNN
    rdnn = RNN(feat.NC, feat.NF, args)

    validator.validate(rdnn, args)