import tensorflow as tf

    "Mean squared error loss"
    loss=tf.reduce_mean(tf.square(tf.reshape(predictions,[-1])-tf.reshape(yy,[-1])))

    "Adding regularization"
    if lambda_l2_reg > 0 :
        cell_l2 = tf.reduce_sum([tf.nn.l2_loss(tf_var) for tf_var in tf.trainable_variables() if not ("noreg" in tf_var.name or "Bias" in tf_var.name)])
        Predict_l2 = tf.nn.l2_loss(W) #+ tf.nn.l2_loss(b)
        total_loss = tf.reduce_sum(loss + lambda_l2_reg* tf.reduce_sum(cell_l2+Predict_l2) )
    else:
        total_loss = loss

    "Define the train_step"
    train_step = tf.train.AdamOptimizer(learning_rate).minimize(total_loss)



    return dict(x=x,
                y=y,
                batch_size=batch_size,
                input_prob=input_prob,
                state_prob=state_prob,
                output_prob=output_prob,
                init_state=init_state,
                final_state=final_state,
