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

32 lines
907 B
ReStructuredText
Raw Normal View History

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