<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/neural-structured-learning/blob/v1.4.0/neural_structured_learning/lib/__init__.py) |

Library APIs for Neural Structured Learning.

## Classes

[`class GenNeighbor`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/GenNeighbor): Abstract class for generating neighbors.

## Functions

[`adv_regularizer(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/adv_regularizer): Calculates adversarial loss from generated adversarial samples.

[`apply_feature_mask(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/apply_feature_mask): Applies a feature mask on `features` if the `feature_mask` is not `None`.

[`decay_over_time(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/decay_over_time): Returns a decayed value of `init_value` over time.

[`gen_adv_neighbor(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/gen_adv_neighbor): Generates adversarial neighbors for the given input and loss.

[`get_target_indices(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/get_target_indices): Selects targeting classes for adversarial attack (classification only).

[`jensen_shannon_divergence(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/jensen_shannon_divergence): Adds a Jensen-Shannon divergence to the training procedure.

[`kl_divergence(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/kl_divergence): Adds a KL-divergence to the training procedure.

[`maximize_within_unit_norm(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/maximize_within_unit_norm): Solves the maximization problem weights\^T\*x with the constraint norm(x)=1.

[`normalize(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/normalize): Normalizes the values in `tensor` with respect to a specified vector norm.

[`pairwise_distance_wrapper(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/pairwise_distance_wrapper): A wrapper to compute the pairwise distance between `sources` and `targets`.

[`project_to_ball(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/project_to_ball): Projects batched tensors to a ball with the given radius in the given norm.

[`random_in_norm_ball(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/random_in_norm_ball): Generates a random sample in a norm ball, conforming the given structure.

[`replicate_embeddings(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/replicate_embeddings): Replicates the given `embeddings` by `replicate_times`.

[`strip_neighbor_features(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/strip_neighbor_features): Strips graph neighbor features from a feature dictionary.

[`unpack_neighbor_features(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/unpack_neighbor_features): Extracts sample features, neighbor features, and neighbor weights.

[`virtual_adv_regularizer(...)`](https://www.tensorflow.org/neural_structured_learning/api_docs/python/nsl/lib/virtual_adv_regularizer): Calculates virtual adversarial loss for the given input.