Exemplo n.º 1
0
def learn_wfsa(wfsa, corpus, distfp=None, checkpoint=None):
    wfsa_ = copy(wfsa)
    wfsa_.round_and_normalize()
    if not checkpoint:
        checkpoint = lambda x: wfsa_.dump(open('{0}.wfsa'.format(x), 'w'))
    if distfp is not None:
        if wfsa_.quantizer is not None:
            bits = int(round(math.log(wfsa_.quantizer.levels, 2)))
            f = [2 ** i for i in xrange(max(0, bits-5), -1, -1)]
            t = [1e-5/2**i for i in xrange(0, max(1, bits-4))]
            learner = Learner(wfsa_, corpus, checkpoint, pref_prob=0.0,
                distfp=distfp, turns_for_each=300, factors=f,
                temperatures=t)
        else:
            # continuous case, not implemented
            pass
        learner.main()
    logging.debug("WFSA learnt")
    return wfsa_