Exemple #1
0
    def get_model(self):
        # Don't need to build the model again, after loading it.
        if self.load_model:
            self.model = load_object_from_file(self.load_model)
            self.skip_examples = self.model.total_examples
            # Don't use the stored learning rate, but the one the user provided.
            # Problem with that: Sometimes we don't want that. Especially when
            # the model should proceed the training with learning rate it has
            # when it stopped training.
            #             self.model.set_learning_rate(float(self.learning_rate),
            #                     self.learning_method, self.lr_adaptation_method)

            if self.period_type == 'time':
                self._last_validation = time()
            else:
                self._last_validation = self.model.total_examples

        else:
            self.model = self.create_model()
            self.model.set_learning_rate(self.learning_rate,
                                         self.learning_method,
                                         self.lr_adaptation_method)

        if self.load_params is not None:
            self.model.load_params(self.load_params[0], self.load_params[1])

        self.model.link(self.inputs)
        self.model.build()
Exemple #2
0
    def get_model(self):
        # Don't need to build the model again, after loading it.
        if self.load_model:
            self.model = load_object_from_file(self.load_model)
            self.skip_examples = self.model.total_examples
            # Don't use the stored learning rate, but the one the user provided.
            # Problem with that: Sometimes we don't want that. Especially when
            # the model should proceed the training with learning rate it has
            # when it stopped training.
#             self.model.set_learning_rate(float(self.learning_rate),
#                     self.learning_method, self.lr_adaptation_method)

            if self.period_type == 'time':
                self._last_validation = time()
            else:
                self._last_validation = self.model.total_examples

        else:
            self.model = self.create_model()
            self.model.set_learning_rate(self.learning_rate,
                    self.learning_method, self.lr_adaptation_method)

        if self.load_params is not None:
            self.model.load_params(self.load_params[0], self.load_params[1])

        self.model.link(self.inputs)
        self.model.build()
Exemple #3
0
def main(argv=None):

    if argv is None:
        argv = sys.argv[1:]

    args = parser.parse_args(argv)
    log.info('start parameters: ' + str(args))

    log.info('loading data')
    model = load_object_from_file(args.model_file)

    log.info('writing data')
    #     trainer.dump_vocabulary(args.vocabulary_file)
    model.store_params(args.store_params[0], args.store_params[1], True,
                       args.format)
    log.info('finished')
def main(argv=None):

    if argv is None:
        argv = sys.argv[1:]

    args = parser.parse_args(argv)
    log.info('start parameters: ' + str(args))

    log.info('loading data')
    model = load_object_from_file(args.model_file)

    log.info('writing data')
#     trainer.dump_vocabulary(args.vocabulary_file)
    model.store_params(args.store_params[0], args.store_params[1], True,
            args.format)
    log.info('finished')
def main(argv=None):

    if argv is None:
        argv = sys.argv[1:]

    args = parser.parse_args(argv)
    log.info('start parameters: ' + str(args))

    log.info('loading data')
    model = load_object_from_file(args.model_file)

    # read vocabulary from file
    vocab = sort_dict_by_label(read_vocabulary_id_file(args.vocabulary))

    # get matrices from model
    r_matrix = model.R.get_value()
    q_matrix = model.Q.get_value()

    # get input embeddings
    if args.model_type == 'vlbl':
        in_we = r_matrix
    elif args.model_type == 'vlbl_dist':
        # this will not work with the old versions of models - because of sparsity
        d_matrix = model.D.get_value().todense()
        in_we = np.dot(d_matrix, r_matrix)
        # need to convert from numpy.matrix to numpy.ndarray
        in_we = in_we.view(type=np.ndarray)

    with utf8_file_open(args.result_file + ".in", 'w') as outfile:
        for (word, ind) in vocab:
            outfile.write(
                unicode(word) + u' ' + u' '.join(map(str, in_we[ind])) + u'\n')

    with utf8_file_open(args.result_file + ".out", 'w') as outfile:
        for (word, ind) in vocab:
            outfile.write(
                unicode(word) + u' ' + u' '.join(map(str, q_matrix[ind])) +
                u'\n')

    log.info('finished')
def main(argv=None):

    if argv is None:
        argv = sys.argv[1:]

    args = parser.parse_args(argv)
    log.info('start parameters: ' + str(args))

    log.info('loading data')
    model = load_object_from_file(args.model_file)

    # read vocabulary from file
    vocab = sort_dict_by_label(read_vocabulary_id_file(args.vocabulary))

    # get matrices from model
    r_matrix = model.R.get_value()
    q_matrix = model.Q.get_value()

    # get input embeddings
    if args.model_type == 'vlbl':
        in_we = r_matrix
    elif args.model_type == 'vlbl_dist':
        # this will not work with the old versions of models - because of sparsity
        d_matrix = model.D.get_value().todense()
        in_we = np.dot(d_matrix, r_matrix)
        # need to convert from numpy.matrix to numpy.ndarray
        in_we = in_we.view(type=np.ndarray)

    with utf8_file_open(args.result_file + ".in", 'w') as outfile:
        for (word, ind) in vocab:
            outfile.write(unicode(word) + u' ' + u' '.join(map(str, in_we[ind])) + u'\n')

    with utf8_file_open(args.result_file + ".out", 'w') as outfile:
        for (word, ind) in vocab:
            outfile.write(unicode(word) + u' ' + u' '.join(map(str, q_matrix[ind])) + u'\n')

    log.info('finished')
Exemple #7
0
 def get_model(self):
     self.model = load_object_from_file(self.load_model)
     self.predictor_method = self.model.predictor
Exemple #8
0
        for i in range(self.training_steps):
            print((self.b.get_value(), type(self.b.get_value())))
            pred, err = self.train(self.D[0], self.D[1])
 
print(floatX)


if not os.path.exists('test'):
    print('create new model')
    model = LogisticRegression()
    model.create_graph()
    model.do_train()
    save_object_to_file(model, 'test')
else:
    print('load model')
    model = load_object_from_file('test')

print("Final model:")
print((model.w.get_value(), model.b.get_value()))
print(("target values for D:", model.D[1]))
print(("prediction on D:", model.predict(model.D[0])))
 

# import numpy
# import theano
# import theano.tensor as T
# from theano import config
# rng = numpy.random
# floatX = config.floatX
# 
# N = 400
Exemple #9
0
 def get_model(self):
     self.model = load_object_from_file(self.load_model)
     self.predictor_method = self.model.predictor
        for i in range(self.training_steps):
            print self.b.get_value(), type(self.b.get_value())
            pred, err = self.train(self.D[0], self.D[1])
 
print floatX


if not os.path.exists('test'):
    print 'create new model'
    model = LogisticRegression()
    model.create_graph()
    model.do_train()
    save_object_to_file(model, 'test')
else:
    print 'load model'
    model = load_object_from_file('test')

print "Final model:"
print model.w.get_value(), model.b.get_value()
print "target values for D:", model.D[1]
print "prediction on D:", model.predict(model.D[0])
 

# import numpy
# import theano
# import theano.tensor as T
# from theano import config
# rng = numpy.random
# floatX = config.floatX
# 
# N = 400