Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

nsl.lib.adv_regularizer

View source on GitHub

Calculates adversarial loss from generated adversarial samples.

nsl.lib.adv_regularizer(
    adv_neighbors,
    target_scores,
    model_fn,
    loss_fn
)

Args:

  • adv_neighbors: dense (float32) tensor, with two possible shapes: (a) pointwise samples: batch_size x feat_len, or (b) sequence samples: batch_size x seq_len x feat_len
  • target_scores: target tensor used to compute loss.
  • model_fn: a method that has input tensor (same shape as adv_neighbors), is_train and reuse as input, returns predicted logits.
  • loss_fn: a loss function that has target and predction as input, and returns a float scalar

Returns:

  • adv_loss: a scalar (float32) for adversarial loss.