nsl.lib.normalize
Stay organized with collections
Save and categorize content based on your preferences.
Normalizes the values in tensor
with respect to a specified vector norm.
nsl.lib.normalize(
tensor, norm_type, epsilon=1e-06
)
This op assumes that the first axis of tensor
is the batch dimension, and
calculates the norm over all other axes. For example, if tensor
is
tf.constant(1.0, shape=[2, 3, 4])
, its L2 norm (calculated along all the
dimensions other than the first dimension) will be [[sqrt(12)], [sqrt(12)]]
.
Hence, this tensor will be normalized by dividing by
[[sqrt(12)], [sqrt(12)]]
.
Note that tf.norm
is not used here since it only allows the norm to be
calculated over one axis, not multiple axes.
Args |
tensor
|
a tensor to be normalized. Can have any shape with the first axis
being the batch dimension that will not be normalized across.
|
norm_type
|
one of nsl.configs.NormType , the type of vector norm.
|
epsilon
|
a lower bound value for the norm to avoid division by 0.
|
Returns |
A normalized tensor with the same shape and type as tensor .
|
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.normalize\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/utils.py#L25-L67) |\n\nNormalizes the values in `tensor` with respect to a specified vector norm. \n\n nsl.lib.normalize(\n tensor, norm_type, epsilon=1e-06\n )\n\nThis op assumes that the first axis of `tensor` is the batch dimension, and\ncalculates the norm over all other axes. For example, if `tensor` is\n`tf.constant(1.0, shape=[2, 3, 4])`, its L2 norm (calculated along all the\ndimensions other than the first dimension) will be `[[sqrt(12)], [sqrt(12)]]`.\nHence, this tensor will be normalized by dividing by\n`[[sqrt(12)], [sqrt(12)]]`.\n\nNote that [`tf.norm`](https://www.tensorflow.org/api_docs/python/tf/norm) is not used here since it only allows the norm to be\ncalculated over one axis, not multiple axes.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|---------------------------------------------------------------------------------------------------------------------------------|\n| `tensor` | a tensor to be normalized. Can have any shape with the first axis being the batch dimension that will not be normalized across. |\n| `norm_type` | one of [`nsl.configs.NormType`](../../nsl/configs/NormType), the type of vector norm. |\n| `epsilon` | a lower bound value for the norm to avoid division by 0. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A normalized tensor with the same shape and type as `tensor`. ||\n\n\u003cbr /\u003e"]]