mindspore/docs/api/api_python/nn/mindspore.nn.L1Regularizer.rst

31 lines
953 B
ReStructuredText
Raw Normal View History

mindspore.nn.L1Regularizer
===========================
.. py:class:: mindspore.nn.L1Regularizer(scale)
对权重计算L1正则化。
2022-06-13 15:37:35 +08:00
L1正则化可导致稀疏权重。
.. math::
\text{loss}=\lambda * \text{reduce_sum}(\text{abs}(\omega))
:math:`\lambda` 代表 `scale`
.. note::
正则化因子应为大于0。
2022-07-22 16:25:38 +08:00
参数:
- **scale** (int, float) - L1正则化因子其值大于0。
2022-07-22 16:25:38 +08:00
输入:
- **weights** (Tensor) - L1Regularizer的输入任意维度的Tensor数据类型为float16或float32。
2022-07-22 16:25:38 +08:00
输出:
Tensor其shape为()默认数据类型为mindspore.float32如果权重的数据类型精度更高则以权重的数据类型作为输出数据类型。
2022-07-22 16:25:38 +08:00
异常:
- **TypeError** - `scale` 既不是int也不是float。
- **ValueError** - `scale` 不大于0。
- **ValueError** - `scale` 是math.inf或math.nan。