tfl.lattice_layer.TorsionRegularizer
Stay organized with collections
Save and categorize content based on your preferences.
Torsion regularizer for tfl.layers.Lattice
layer.
tfl.lattice_layer.TorsionRegularizer(
lattice_sizes, l1=0.0, l2=0.0
)
Lattice torsion regularizer penalizes how much the lattice function twists
from side-to-side (see
publication).
Consider a 3 x 2 lattice with weights w
:
w[3]-----w[4]-----w[5]
| | |
| | |
w[0]-----w[1]-----w[2]
In this case, the torsion regularizer is defined as:
l1 * (|w[4] + w[0] - w[3] - w[1]| + |w[5] + w[1] - w[4] - w[2]|) +
l2 * ((w[4] + w[0] - w[3] - w[1])^2 + (w[5] + w[1] - w[4] - w[2])^2)
Args |
lattice_sizes
|
Lattice sizes of tfl.layers.Lattice to regularize.
|
l1
|
l1 regularization amount. Either single float or list or tuple of
floats to specify different regularization amount per dimension. The
amount of regularization for the interaction term between two dimensions
is the product of the corresponding per dimension amounts.
|
l2
|
l2 regularization amount. Either single float or list or tuple of
floats to specify different regularization amount per dimension. The
amount of regularization for the interaction term between two dimensions
is the product of the corresponding per dimension amounts.
|
Methods
from_config
@classmethod
from_config(
config
)
Creates a regularizer from its config.
This method is the reverse of get_config
,
capable of instantiating the same regularizer from the config
dictionary.
This method is used by TF-Keras model_to_estimator
, saving and
loading models to HDF5 formats, TF-Keras model cloning, some
visualization utilities, and exporting models to and from JSON.
Args |
config
|
A Python dictionary, typically the output of get_config.
|
Returns |
A regularizer instance.
|
get_config
View source
get_config()
Standard Keras config for serialization.
__call__
View source
__call__(
x
)
Returns regularization loss for x
.
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 2024-08-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-02 UTC."],[],[],null,["# tfl.lattice_layer.TorsionRegularizer\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L938-L998) |\n\nTorsion regularizer for [`tfl.layers.Lattice`](../../tfl/layers/Lattice) layer. \n\n tfl.lattice_layer.TorsionRegularizer(\n lattice_sizes, l1=0.0, l2=0.0\n )\n\nLattice torsion regularizer penalizes how much the lattice function twists\nfrom side-to-side (see\n[publication](http://jmlr.org/papers/v17/15-243.html)).\n\nConsider a 3 x 2 lattice with weights `w`: \n\n w[3]-----w[4]-----w[5]\n | | |\n | | |\n w[0]-----w[1]-----w[2]\n\nIn this case, the torsion regularizer is defined as: \n\n l1 * (|w[4] + w[0] - w[3] - w[1]| + |w[5] + w[1] - w[4] - w[2]|) +\n l2 * ((w[4] + w[0] - w[3] - w[1])^2 + (w[5] + w[1] - w[4] - w[2])^2)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `lattice_sizes` | Lattice sizes of [`tfl.layers.Lattice`](../../tfl/layers/Lattice) to regularize. |\n| `l1` | l1 regularization amount. Either single float or list or tuple of floats to specify different regularization amount per dimension. The amount of regularization for the interaction term between two dimensions is the product of the corresponding per dimension amounts. |\n| `l2` | l2 regularization amount. Either single float or list or tuple of floats to specify different regularization amount per dimension. The amount of regularization for the interaction term between two dimensions is the product of the corresponding per dimension amounts. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n @classmethod\n from_config(\n config\n )\n\nCreates a regularizer from its config.\n\nThis method is the reverse of `get_config`,\ncapable of instantiating the same regularizer from the config\ndictionary.\n\nThis method is used by TF-Keras `model_to_estimator`, saving and\nloading models to HDF5 formats, TF-Keras model cloning, some\nvisualization utilities, and exporting models to and from JSON.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|----------------------------------------------------------|\n| `config` | A Python dictionary, typically the output of get_config. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A regularizer instance. ||\n\n\u003cbr /\u003e\n\n### `get_config`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L992-L998) \n\n get_config()\n\nStandard Keras config for serialization.\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/lattice_layer.py#L985-L990) \n\n __call__(\n x\n )\n\nReturns regularization loss for `x`."]]