2022-02-12 11:07:52 +08:00
|
|
|
|
mindspore.nn.L1Regularizer
|
|
|
|
|
|
===========================
|
|
|
|
|
|
|
|
|
|
|
|
.. py:class:: mindspore.nn.L1Regularizer(scale)
|
|
|
|
|
|
|
2022-03-25 14:21:05 +08:00
|
|
|
|
对权重计算L1正则化。
|
2022-02-12 11:07:52 +08:00
|
|
|
|
|
|
|
|
|
|
.. math::
|
|
|
|
|
|
\text{loss}=\lambda * \text{reduce_sum}(\text{abs}(\omega))
|
|
|
|
|
|
|
2022-03-25 14:21:05 +08:00
|
|
|
|
:math:`\lambda` 代表 `scale` 。
|
|
|
|
|
|
|
2022-02-12 11:07:52 +08:00
|
|
|
|
.. note::
|
|
|
|
|
|
正则化因子应为大于0。
|
|
|
|
|
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
2022-03-04 15:40:30 +08:00
|
|
|
|
- **scale** (int, float) - L1正则化因子,其值大于0。
|
2022-02-12 11:07:52 +08:00
|
|
|
|
|
|
|
|
|
|
**输入:**
|
|
|
|
|
|
|
2022-03-04 15:40:30 +08:00
|
|
|
|
- **weights** (Tensor) - L1Regularizer的输入,任意维度的Tensor,数据类型为float16或float32。
|
2022-02-12 11:07:52 +08:00
|
|
|
|
|
|
|
|
|
|
**输出:**
|
|
|
|
|
|
|
|
|
|
|
|
Tensor,其shape为(),默认数据类型为mindspore.float32,如果权重的数据类型精度更高,则以权重的数据类型作为输出数据类型。
|
|
|
|
|
|
|
|
|
|
|
|
**异常:**
|
|
|
|
|
|
|
|
|
|
|
|
- **TypeError** - `scale` 既不是int也不是float。
|
|
|
|
|
|
- **ValueError** - `scale` 不大于0。
|
|
|
|
|
|
- **ValueError** - `scale` 是math.inf或math.nan。
|