Beispiel #1
0
def work():
    config_dict = yaml.load(open(sys.argv[1], 'r'))
    print config_dict

    if config_dict['working_mode'] == 'train_new':
        train, valid, alphabet = build_datasets(config_dict)
        generator, cost = build_model(len(alphabet), config_dict)
        algorithm = build_algorithm(generator, cost, config_dict)
        extensions = build_extensions(cost, algorithm, valid, config_dict)
        main_loop = MainLoop(algorithm=algorithm, data_stream=train,
                             model=Model(cost), extensions=extensions)
        main_loop.run()

    elif config_dict['working_mode'] == 'train_resume':
        # TODO
        pass
    def __init__(self, config_dict):
        print config_dict
        train, valid, alphabet = build_datasets(config_dict)
        generator, cost = build_model(len(alphabet), config_dict)
        algorithm = build_algorithm(generator, cost, config_dict)
        extensions = build_extensions(cost, algorithm, valid, config_dict)
        main_loop = MainLoop(algorithm=algorithm, data_stream=train,
                             model=Model(cost), extensions=extensions)
        ml = Load(config_dict['checkpoint_path'], load_log=True)
        ml.load_to(main_loop)
        generator = main_loop.model.get_top_bricks()[-1]
        
        self.numbers_from_text = pickle.load(open(config_dict['dict_path']))

        x = tensor.lmatrix('sample')
        cost_cg = generator.cost(x)
        self.cost_f = theano.function([x], cost_cg)
Beispiel #3
0
import yaml
from data import build_datasets
from model import build_model, build_algorithm
from monitor import build_extensions
from blocks.main_loop import MainLoop
from blocks.model import Model
from blocks.extensions.saveload import Load
import cPickle as pickle
from blocks.graph import ComputationGraph

config_dict = yaml.load(open(sys.argv[1], 'r'))
print config_dict

train, valid, alphabet = build_datasets(config_dict)
generator, cost = build_model(len(alphabet), config_dict)
algorithm = build_algorithm(generator, cost, config_dict)
extensions = build_extensions(cost, algorithm, valid, config_dict)
main_loop = MainLoop(algorithm=algorithm, data_stream=train,
                     model=Model(cost), extensions=extensions)
ml = Load(config_dict['checkpoint_path'], load_log=True)
print dir(ml)

ml.load_to(main_loop)
generator = main_loop.model.get_top_bricks()[-1]

sampler = ComputationGraph(generator.generate(
    n_steps=1000, batch_size=10, iterate=True)).get_theano_function()

samples = sampler()
outputs = samples[-2]
charset = pickle.load(open(config_dict['dict_path']))