def total_norm_constraint(tensor_vars, max_norm, epsilon=1e-07, return_norm=False):
 norm = T.sqrt(sum((T.sum((tensor ** 2)) for tensor in tensor_vars)))
 dtype = np.dtype(theano.config.floatX).type
 target_norm = T.clip(norm, 0, dtype(max_norm))
 multiplier = (target_norm / (dtype(epsilon) + norm))
 tensor_vars_scaled = [(step * multiplier) for step in tensor_vars]
 if return_norm:
  return (tensor_vars_scaled, norm)
 else:
  return tensor_vars_scaled

def total_norm_constraint ( tensor_vars , max_norm , epsilon = 1e-07 , return_norm = False ) : norm = T . sqrt ( sum ( ( T . sum ( ( tensor ** 2 ) ) for tensor in tensor_vars ) ) ) dtype = np . dtype ( theano . config . floatX ) . type target_norm = T . clip ( norm , 0 , dtype ( max_norm ) ) multiplier = ( target_norm / ( dtype ( epsilon ) + norm ) ) tensor_vars_scaled = [ ( step * multiplier ) for step in tensor_vars ] if return_norm : return ( tensor_vars_scaled , norm ) else : return tensor_vars_scaled
rescales a list of tensors based on their combined norm if the combined norm of the input tensors exceeds the threshold then all tensors are rescaled such that the combined norm is equal to the threshold .