def cost(self, readouts, outputs): mu, sigma, coeff = self.components(readouts) #ipdb.set_trace() return GMM(outputs, mu, sigma, coeff)
bricks = [mlp_x, transition, mlp_gmm] for brick in bricks: brick.weights_init = IsotropicGaussian(0.01) brick.biases_init = Constant(0.) brick.initialize() ############## # Test model ############## x_g = mlp_x.apply(x) h = transition.apply(x_g) mu, sigma, coeff = mlp_gmm.apply(h[-2]) cost = GMM(y, mu, sigma, coeff) cost = cost.mean() cost.name = 'sequence_log_likelihood' cg = ComputationGraph(cost) model = Model(cost) ################# # Algorithm ################# n_batches = 139 * 16 algorithm = GradientDescent(cost=cost, parameters=cg.parameters, step_rule=CompositeRule(
############## # Test model ############## x_g = mlp_x.apply(x) h = transition.apply(x_g) mu, sigma, coeff = mlp_gmm.apply(h[-2]) #from theano import function #x_tr, x_mask_tr, y_tr = next(data_stream.get_epoch_iterator()) #print function([x], x_g)(x_tr).shape #print function([x], h)(x_tr)[-2].shape #print function([x], mu)(x_tr).shape from play.utils import GMM cost = GMM(y, mu, sigma, coeff) cost = cost*x_mask cost = cost.sum()/x_mask.sum() cost.name = 'sequence_log_likelihood' cg = ComputationGraph(cost) model = Model(cost) #ipdb.set_trace() #x_tr, x_mask_tr, y_tr = next(data_stream.get_epoch_iterator()) #print function([x, x_mask, y], cost)(x_tr, x_mask_tr, y_tr) ################# # Algorithm #################
bricks = [mlp_x, transition, mlp_gmm] for brick in bricks: brick.weights_init = IsotropicGaussian(0.01) brick.biases_init = Constant(0.) brick.initialize() ############## # Test model ############## x_g = mlp_x.apply(x) h = transition.apply(x_g) mu, sigma, coeff = mlp_gmm.apply(h[-2]) cost = GMM(y, mu, sigma, coeff) cost = cost.mean() cost.name = 'sequence_log_likelihood' cg = ComputationGraph(cost) model = Model(cost) ################# # Algorithm ################# n_batches = 139*16 algorithm = GradientDescent( cost=cost, parameters=cg.parameters, step_rule=CompositeRule([StepClipping(10.0), Adam(lr)]))