tfl.configs.RegularizerConfig
Stay organized with collections
Save and categorize content based on your preferences.
Regularizer configuration for TFL canned estimators.
tfl.configs.RegularizerConfig(
name, l1=0.0, l2=0.0
)
Used in the notebooks
Regularizers can either be applied to specific features, or can be applied
globally to all features or lattices.
Examples:
model_config = tfl.configs.CalibratedLatticeConfig(
feature_configs=[
tfl.configs.FeatureConfig(
name='age',
lattice_size=3,
# Per feature regularization.
regularizer_configs=[
tfl.configs.RegularizerConfig(name='calib_hessian', l2=1e-4),
],
),
tfl.configs.FeatureConfig(
name='thal',
# Partial monotonicity:
# output(normal) <= output(fixed)
# output(normal) <= output(reversible)
monotonicity=[('normal', 'fixed'), ('normal', 'reversible')],
),
],
# Global regularizers
regularizer_configs=[
# Torsion regularizer applied to the lattice to make it more linear.
configs.RegularizerConfig(name='torsion', l2=1e-4),
# Globally defined calibration regularizer is applied to all features.
configs.RegularizerConfig(name='calib_hessian', l2=1e-4),
])
feature_analysis_input_fn = create_input_fn(num_epochs=1, ...)
train_input_fn = create_input_fn(num_epochs=100, ...)
estimator = tfl.estimators.CannedClassifier(
feature_columns=feature_columns,
model_config=model_config,
feature_analysis_input_fn=feature_analysis_input_fn)
estimator.train(input_fn=train_input_fn)
Args |
name
|
The name of the regularizer.
|
l1
|
l1 regularization amount.
|
l2
|
l2 regularization amount.
|
Methods
deserialize_nested_configs
View source
@classmethod
deserialize_nested_configs(
config, custom_objects=None
)
Returns a deserialized configuration dictionary.
from_config
View source
@classmethod
from_config(
config, custom_objects=None
)
get_config
View source
get_config()
Returns a configuration dictionary.
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.
[null,null,["Last updated 2024-08-02 UTC."],[],[],null,["# tfl.configs.RegularizerConfig\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L843-L935) |\n\nRegularizer configuration for TFL canned estimators. \n\n tfl.configs.RegularizerConfig(\n name, l1=0.0, l2=0.0\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [TF Lattice Premade Models](https://www.tensorflow.org/lattice/tutorials/premade_models) - [Shape Constraints with Tensorflow Lattice](https://www.tensorflow.org/lattice/tutorials/shape_constraints) |\n\nRegularizers can either be applied to specific features, or can be applied\nglobally to all features or lattices.\n\n- **Calibrator regularizers:**\n\n These regularizers are applied to PWL calibration layers.\n - `'calib_laplacian'`: Creates an instance of [`tfl.pwl_calibration_layer.LaplacianRegularizer`](../../tfl/pwl_calibration_layer/LaplacianRegularizer). A calibrator laplacian regularizer penalizes the changes in the output and results in a *flatter\n calibration function*.\n - `'calib_hessian'`: Creates an instance of [`tfl.pwl_calibration_layer.HessianRegularizer`](../../tfl/pwl_calibration_layer/HessianRegularizer). A calibrator hessian regularizer penalizes changes in the slope, resulting in a *more linear\n calibration*.\n - `'calib_wrinkle'`: Creates an instance of [`tfl.pwl_calibration_layer.WrinkleRegularizer`](../../tfl/pwl_calibration_layer/WrinkleRegularizer). A calibrator wrinkle regularizer penalizes the second derivative, resulting in a smoother function with *less changes in the curvature*.\n- **Lattice regularizers:**\n\n These regularizers are applied to lattice layers.\n - `'laplacian'`: Creates an instance of [`tfl.lattice_layer.LaplacianRegularizer`](../../tfl/lattice_layer/LaplacianRegularizer). Laplacian regularizers penalize the difference between adjacent vertices in multi-cell lattice, resulting in a *flatter lattice function*.\n - `'torsion'`: Creates an instance of [`tfl.lattice_layer.TorsionRegularizer`](../../tfl/lattice_layer/TorsionRegularizer). Torsion regularizers penalizes how much the lattice function twists from side-to-side, a non-linear interactions in each 2 x 2 cell. Using this regularization results in a *more linear lattice function*.\n\n#### Examples:\n\n model_config = tfl.configs.CalibratedLatticeConfig(\n feature_configs=[\n tfl.configs.FeatureConfig(\n name='age',\n lattice_size=3,\n # Per feature regularization.\n regularizer_configs=[\n tfl.configs.RegularizerConfig(name='calib_hessian', l2=1e-4),\n ],\n ),\n tfl.configs.FeatureConfig(\n name='thal',\n # Partial monotonicity:\n # output(normal) \u003c= output(fixed)\n # output(normal) \u003c= output(reversible)\n monotonicity=[('normal', 'fixed'), ('normal', 'reversible')],\n ),\n ],\n # Global regularizers\n regularizer_configs=[\n # Torsion regularizer applied to the lattice to make it more linear.\n configs.RegularizerConfig(name='torsion', l2=1e-4),\n # Globally defined calibration regularizer is applied to all features.\n configs.RegularizerConfig(name='calib_hessian', l2=1e-4),\n ])\n feature_analysis_input_fn = create_input_fn(num_epochs=1, ...)\n train_input_fn = create_input_fn(num_epochs=100, ...)\n estimator = tfl.estimators.CannedClassifier(\n feature_columns=feature_columns,\n model_config=model_config,\n feature_analysis_input_fn=feature_analysis_input_fn)\n estimator.train(input_fn=train_input_fn)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|------------------------------|\n| `name` | The name of the regularizer. |\n| `l1` | l1 regularization amount. |\n| `l2` | l2 regularization amount. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `deserialize_nested_configs`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L124-L158) \n\n @classmethod\n deserialize_nested_configs(\n config, custom_objects=None\n )\n\nReturns a deserialized configuration dictionary.\n\n### `from_config`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L932-L935) \n\n @classmethod\n from_config(\n config, custom_objects=None\n )\n\n### `get_config`\n\n[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L93-L122) \n\n get_config()\n\nReturns a configuration dictionary."]]