cell = tf.contrib.rnn.GRUCell(EMBEDDING_SIZE)
_, encoding = tf.contrib.rnn.static_rnn(cell, word_list, dtype=tf.float32 )
with tf.variable_scope('linear_regression'):
y_shape = y.get_shape()
output_shape = y_shape[1]
weights = tf.get_variable('weights', [encoding.get_shape()[1], output_shape])
bias = tf.get_variable('bias', [output_shape])
with tf.op_scope([encoding, y], name, "mean_squared_error_regressor"):
predictions = tf.nn.xw_plus_b(encoding, weights, bias)
predictions_dict = { "prediction": predictions }
if len(y.get_shape()) == 1:
y = tf.reshape(y, [-1, 1])
loss = tf.losses.mean_squared_error( y , predictions)
eval_metric_ops = {
"rmse": tf.metrics.root_mean_squared_error( y, predictions)
}
train_op = tf.contrib.layers.optimize_loss( loss, tf.contrib.framework.get_global_step(), optimizer='Adam', learning_rate=0.01)
return model_fn_lib.ModelFnOps(
mode=mode,
predictions=predictions_dict,
loss=loss,
train_op=train_op,
eval_metric_ops=eval_metric_ops)