nsl.lib.virtual_adv_regularizer
Stay organized with collections
Save and categorize content based on your preferences.
Calculates virtual adversarial loss for the given input.
nsl.lib.virtual_adv_regularizer(
input_layer, embedding_fn, virtual_adv_config, embedding=None
)
Virtual adversarial loss is defined as the distance between the embedding of
the input and that of a slightly perturbed input. Optimizing this loss helps
smooth models locally.
Reference paper: https://arxiv.org/pdf/1704.03976.pdf
Args |
input_layer
|
a dense tensor for input features whose first dimension is the
training batch size.
|
embedding_fn
|
a unary function that computes the embedding for the given
input_layer input.
|
virtual_adv_config
|
an nsl.configs.VirtualAdvConfig object that specifies
parameters for generating adversarial examples and computing the
adversarial loss.
|
embedding
|
(optional) a dense tensor representing the embedding of
input_layer . If not provided, it will be calculated as
embedding_fn(input_layer) .
|
Returns |
virtual_adv_loss
|
a float32 denoting the virtural adversarial loss.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-10-28 UTC.
[null,null,["Last updated 2022-10-28 UTC."],[],[],null,["# nsl.lib.virtual_adv_regularizer\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/lib/regularizer.py#L83-L116) |\n\nCalculates virtual adversarial loss for the given input. \n\n nsl.lib.virtual_adv_regularizer(\n input_layer, embedding_fn, virtual_adv_config, embedding=None\n )\n\nVirtual adversarial loss is defined as the distance between the embedding of\nthe input and that of a slightly perturbed input. Optimizing this loss helps\nsmooth models locally.\n\nReference paper: \u003chttps://arxiv.org/pdf/1704.03976.pdf\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_layer` | a dense tensor for input features whose first dimension is the training batch size. |\n| `embedding_fn` | a unary function that computes the embedding for the given `input_layer` input. |\n| `virtual_adv_config` | an [`nsl.configs.VirtualAdvConfig`](../../nsl/configs/VirtualAdvConfig) object that specifies parameters for generating adversarial examples and computing the adversarial loss. |\n| `embedding` | (optional) a dense tensor representing the embedding of `input_layer`. If not provided, it will be calculated as `embedding_fn(input_layer)`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|--------------------|-----------------------------------------------------|\n| `virtual_adv_loss` | a `float32` denoting the virtural adversarial loss. |\n\n\u003cbr /\u003e"]]