Determines whether a health pill event contains bad values.

  A bad value is one of NaN, -Inf, or +Inf.

  Args:
    event: (`Event`) A `tensorflow.Event` proto from `DebugNumericSummary`
      ops.

  Returns:
    An instance of `NumericsAlert`, if bad values are found.
    `None`, if no bad values are found.

  Raises:
    ValueError: if the event does not have the expected tag prefix or the
      debug op name is not the expected debug op name suffix.

def extract_numerics_alert(event):
  """Determines whether a health pill event contains bad values.

  A bad value is one of NaN, -Inf, or +Inf.

  Args:
    event: (`Event`) A `tensorflow.Event` proto from `DebugNumericSummary`
      ops.

  Returns:
    An instance of `NumericsAlert`, if bad values are found.
    `None`, if no bad values are found.

  Raises:
    ValueError: if the event does not have the expected tag prefix or the
      debug op name is not the expected debug op name suffix.
  """
  value = event.summary.value[0]
  debugger_plugin_metadata_content = None
  if value.HasField("metadata"):
    plugin_data = value.metadata.plugin_data
    if plugin_data.plugin_name == constants.DEBUGGER_PLUGIN_NAME:
      debugger_plugin_metadata_content = plugin_data.content

  if not debugger_plugin_metadata_content:
    raise ValueError("Event proto input lacks debugger plugin SummaryMetadata.")

  debugger_plugin_metadata_content = tf.compat.as_text(
      debugger_plugin_metadata_content)
  try:
    content_object = json.loads(debugger_plugin_metadata_content)
    device_name = content_object["device"]
  except (KeyError, ValueError) as e:
    raise ValueError("Could not determine device from JSON string %r, %r" %
                     (debugger_plugin_metadata_content, e))

  debug_op_suffix = ":DebugNumericSummary"
  if not value.node_name.endswith(debug_op_suffix):
    raise ValueError(
        "Event proto input does not have the expected debug op suffix %s" %
        debug_op_suffix)
  tensor_name = value.node_name[:-len(debug_op_suffix)]

  elements = tf_debug.load_tensor_from_event(event)
  nan_count = elements[constants.NAN_NUMERIC_SUMMARY_OP_INDEX]
  neg_inf_count = elements[constants.NEG_INF_NUMERIC_SUMMARY_OP_INDEX]
  pos_inf_count = elements[constants.POS_INF_NUMERIC_SUMMARY_OP_INDEX]
  if nan_count > 0 or neg_inf_count > 0 or pos_inf_count > 0:
    return NumericsAlert(
        device_name, tensor_name, event.wall_time, nan_count, neg_inf_count,
        pos_inf_count)
  return None