Exemplo n.º 1
0
 def inference(params=None):
     x, _ = input_data([None, 5], name='x')
     y, _ = input_data([None, 5], name='y')
     x1, _ = fully_connected_network(x, [5, 1], name='x1')
     y1, _ = fully_connected_network(y, [5, 1], name='y1')
     d, _ = angle_distance(x1 + y1, name='d')
     return d
Exemplo n.º 2
0
def sentence_encoder(emb_sentence, params, name='encoded_sentence'):
	"""
	@param emb_sentence:
	@param params:
	@return:
	"""
	conv_num_features = utils.get_dict_value(params, 'conv_num_features', [[100,100,100],[100]])
	conv_widths = utils.get_dict_value(params, 'conv_widths', [[2,3,4],[3]])
	conv_keep_probs = utils.get_dict_value(params, 'conv_keep_probs', 0.5)
	mlp_config = utils.get_dict_value(params, 'mlp_config', [512])
	bipass_conv = utils.get_dict_value(params, 'bipass_conv', False)
	mlp_activations = utils.get_dict_value(params, 'mlp_activations', 'sigmoid')
	mlp_dropout_keep_probs = utils.get_dict_value(params, 'mlp_keep_probs', 0.9)
	use_no_conv_path = utils.get_dict_value(params, 'use_no_conv_path', False)
	if bipass_conv:
		conv_group = [emb_sentence]
	else:
		if use_no_conv_path:
			conv_group = [emb_sentence]
		else:
			conv_group = []
		for i, (conv_num_feature, conv_width) in enumerate(zip(conv_num_features, conv_widths)):
			conv_out = nlp.conv1d_array(emb_sentence, conv_num_feature, conv_width,name='conv%s'%(str(i)), w_wds=0.000, b_wds=0.000, keep_probs=conv_keep_probs)
			conv_group.append(conv_out)
	conv_out, _ = misc.concat(conv_group)
	mlp_out, _ = mlp.fully_connected_network(conv_out, mlp_config, layer_activations=mlp_activations, dropout_keep_probs=mlp_dropout_keep_probs)
	return [tf.identity(mlp_out[0], name=name)], {}
Exemplo n.º 3
0
def sentence_encoder(emb_sentence, word_emb, params, name='encoded_sentence'):
	"""
	@param emb_sentence:
	@param params:
	@return:
	"""
	conv_num_features = utils.get_dict_value(params, 'conv_num_features')
	conv_widths = utils.get_dict_value(params, 'conv_widths')
	conv_keep_probs = utils.get_dict_value(params, 'conv_keep_probs')
	mlp_config = utils.get_dict_value(params, 'mlp_config')
	bipass_conv = utils.get_dict_value(params, 'bipass_conv')
	mlp_activations = utils.get_dict_value(params, 'mlp_activations')
	mlp_dropout_keep_probs = utils.get_dict_value(params, 'mlp_keep_probs')
	use_no_conv_path = utils.get_dict_value(params, 'use_no_conv_path')

	char_conv_num_features = utils.get_dict_value(params, 'char_conv_num_features')
	char_conv_widths = utils.get_dict_value(params, 'char_conv_widths')
	char_use_no_conv_path = utils.get_dict_value(params, 'char_use_no_conv_path', False)
	char_conv_keep_probs = utils.get_dict_value(params, 'char_conv_keep_probs')

	char_weight_wd_regularization = utils.get_dict_value(params, 'char_weight_wd_regularization', 0.0)
	char_bias_wd_regularization = utils.get_dict_value(params, 'char_bias_wd_regularization', 0.0)
	word_weight_wd_regularization = utils.get_dict_value(params, 'word_weight_wd_regularization', 0.0)
	word_bias_wd_regularization = utils.get_dict_value(params, 'word_bias_wd_regularization', 0.0)

	if bipass_conv:
		conv_group = [emb_sentence]
	else:
		if use_no_conv_path:
			conv_group = [emb_sentence]
		else:
			conv_group = []
		for i, (conv_num_feature, conv_width) in enumerate(zip(conv_num_features, conv_widths)):
			conv_out = nlp.conv1d_array(emb_sentence, conv_num_feature, conv_width,name='conv%s'%(str(i)),
																	w_wds=word_weight_wd_regularization,
																	b_wds=word_bias_wd_regularization, keep_probs=conv_keep_probs)
			conv_group.append(conv_out)

	# deal with the word path
	if (char_conv_widths is not None) and (char_conv_num_features is not None):
		if char_use_no_conv_path:
			conv_group.append(word_emb)
		for i, (char_conv_num_feature, char_conv_width) in enumerate(zip(char_conv_num_features, char_conv_widths)):
			conv_out = nlp.conv1d_array(word_emb, char_conv_num_feature, char_conv_width,name='char_conv%s'%(str(i)),
								 				 w_wds = char_weight_wd_regularization,
												 b_wds = char_bias_wd_regularization, keep_probs=char_conv_keep_probs)
			conv_group.append(conv_out)
	else:
		conv_group.append(word_emb)

	conv_out, _ = misc.concat(conv_group)
	mlp_out, _ = mlp.fully_connected_network(conv_out, mlp_config, layer_activations=mlp_activations, dropout_keep_probs=mlp_dropout_keep_probs)
	return [tf.identity(mlp_out[0], name=name)], {}
Exemplo n.º 4
0
def inference(params):
    feature_count = utils.get_dict_value(params, 'feature_count')
    mlp_config = utils.get_dict_value(params, 'mlp_config')
    mlp_activations = utils.get_dict_value(params, 'mlp_activations')
    mlp_dropout_keep_probs = utils.get_dict_value(params,
                                                  'mlp_dropout_keep_probs')
    x = tf.placeholder(tf.float32, [None, feature_count], 'features')
    mlp_out, _ = mlp.fully_connected_network(
        [x],
        mlp_config,
        layer_activations=mlp_activations,
        dropout_keep_probs=mlp_dropout_keep_probs)
    return mlp_out, _