code: def regularization(variables, regtype, regcoef, name="regularization"):
          
          with tf.name_scope(name):
              if regtype != 'none':
                  regs = tf.constant(0.0)
                  for v in variables:
                      if regtype == 'l2':
                          regs = tf.add(regs, tf.nn.l2_loss(v))
                      elif regtype == 'l1':
                          regs = tf.add(regs, tf.reduce_sum(tf.abs(v)))
  
                  return tf.multiply(regcoef, regs)
              else:
                  return None
docs: Compute the regularization tensor.
  
          Parameters
          ----------
  
          variables : list of tf.Variable
              List of model variables.
  
          regtype : str
              Type of regularization. Can be ["none", "l1", "l2"]
  
          regcoef : float,
              Regularization coefficient.
  
          name : str, optional (default = "regularization")
              Name for the regularization op.
  
          Returns
          -------
  
          tf.Tensor : Regularization tensor.