import tensorflow as tf

	with tf.variable_scope(args.name):
		model = HredModel(data, args, embed)
		model.print_parameters()
		latest_dir = '%s/checkpoint_latest' % args.model_dir
		best_dir = '%s/checkpoint_best' % args.model_dir
		if tf.train.get_checkpoint_state(latest_dir) and args.restore == "last":
			print("Reading model parameters from %s" % latest_dir)
			model.latest_saver.restore(sess, tf.train.latest_checkpoint(latest_dir))
		else:
			if tf.train.get_checkpoint_state(best_dir) and args.restore == "best":
				print('Reading model parameters from %s' % best_dir)
				model.best_saver.restore(sess, tf.train.latest_checkpoint(best_dir))
			else:
				print("Created model with fresh parameters.")
				global_variable = [gv for gv in tf.global_variables() if args.name in gv.name]
				sess.run(tf.variables_initializer(global_variable))

	return model
