class_docstr: Types of loss reduction.
  
  Contains the following values:
  
  * `NONE`: Un-reduced weighted losses with the same shape as input.
  * `SUM`: Scalar sum of weighted losses.
  * `MEAN`: Scalar `SUM` divided by sum of weights. DEPRECATED.
  * `SUM_OVER_BATCH_SIZE`: Scalar `SUM` divided by number of elements in losses.
  * `SUM_OVER_NONZERO_WEIGHTS`: Scalar `SUM` divided by number of non-zero
     weights. DEPRECATED.
  * `SUM_BY_NONZERO_WEIGHTS`: Same as `SUM_OVER_NONZERO_WEIGHTS`. DEPRECATED.
class_docstr_tok: ["Types","of","loss","reduction",".","Contains","the","following","values",":","*","`","NONE","`",":","Un-reduced","weighted","losses","with","the","same","shape","as","input",".","*","`","SUM","`",":","Scalar","sum","of","weighted","losses",".","*","`","MEAN","`",":","Scalar","`","SUM","`","divided","by","sum","of","weights",".","DEPRECATED",".","*","`","SUM_OVER_BATCH_SIZE","`",":","Scalar","`","SUM","`","divided","by","number","of","elements","in","losses",".","*","`","SUM_OVER_NONZERO_WEIGHTS","`",":","Scalar","`","SUM","`","divided","by","number","of","non-zero","weights",".","DEPRECATED",".","*","`","SUM_BY_NONZERO_WEIGHTS","`",":","Same","as","`","SUM_OVER_NONZERO_WEIGHTS","`",".","DEPRECATED","."]
code: def validate(cls, key):
      if key not in cls.all():
          raise ValueError(
              f"Invalid Reduction Key {key}. Key should be one of "
              f"{cls.all()}."
          )
  
imports: from tensorflow.python.eager import context
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import confusion_matrix
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import weights_broadcast_ops
  from tensorflow.python.ops.losses import util
  from tensorflow.python.util import dispatch
  from tensorflow.python.util.deprecation import deprecated_args
  from tensorflow.python.util.deprecation import deprecated_argument_lookup
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 2 for calling the Reduction obj's underlying member method code with example usage: obj.validate(cls, key) without return types