def get_train_op(self,<EOL>loss,<EOL>learning_rate,<EOL>optimizer=None,<EOL>clip_norm=None,<EOL>learnable_scopes=None,<EOL>optimizer_scope_name=None,<EOL>**kwargs):
if optimizer_scope_name is None:<EOL><INDENT>opt_scope = tf.variable_scope('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>opt_scope = tf.variable_scope(optimizer_scope_name)<EOL><DEDENT>with opt_scope:<EOL><INDENT>if learnable_scopes is None:<EOL><INDENT>variables_to_train = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)<EOL><DEDENT>else:<EOL><INDENT>variables_to_train = []<EOL>for scope_name in learnable_scopes:<EOL><INDENT>variables_to_train.extend(tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope=scope_name))<EOL><DEDENT><DEDENT>if optimizer is None:<EOL><INDENT>optimizer = tf.train.AdamOptimizer<EOL><DEDENT>extra_update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)<EOL>with tf.control_dependencies(extra_update_ops):<EOL><INDENT>def clip_if_not_none(grad):<EOL><INDENT>if grad is not None:<EOL><INDENT>return tf.clip_by_norm(grad, clip_norm)<EOL><DEDENT><DEDENT>opt = optimizer(learning_rate, **kwargs)<EOL>grads_and_vars = opt.compute_gradients(loss, var_list=variables_to_train)<EOL>if clip_norm is not None:<EOL><INDENT>grads_and_vars = [(clip_if_not_none(grad), var)<EOL>for grad, var in grads_and_vars]<EOL><DEDENT>train_op = opt.apply_gradients(grads_and_vars)<EOL><DEDENT><DEDENT>return train_op<EOL>
Get train operation for given loss

Args:
    loss: loss, tf tensor or scalar
    learning_rate: scalar or placeholder.
    clip_norm: clip gradients norm by clip_norm.
    learnable_scopes: which scopes are trainable (None for all).
    optimizer: instance of tf.train.Optimizer, default Adam.
    **kwargs: parameters passed to tf.train.Optimizer object
       (scalars or placeholders).

Returns:
    train_op