From 299f4f54e1f19266103df7143c50fe66f21a4a50 Mon Sep 17 00:00:00 2001 From: zhangjingwei <57820731+Ainavo@users.noreply.github.com> Date: Wed, 5 Jul 2023 16:29:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9COPY-FROM=20No.15=20regulariz?= =?UTF-8?q?er=20(#5961)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/paddle/regularizer/L1Decay_cn.rst | 38 ++-------------------- docs/api/paddle/regularizer/L2Decay_cn.rst | 38 ++-------------------- 2 files changed, 4 insertions(+), 72 deletions(-) diff --git a/docs/api/paddle/regularizer/L1Decay_cn.rst b/docs/api/paddle/regularizer/L1Decay_cn.rst index 50ecc1a82d6..53d8eb5df23 100644 --- a/docs/api/paddle/regularizer/L1Decay_cn.rst +++ b/docs/api/paddle/regularizer/L1Decay_cn.rst @@ -28,44 +28,10 @@ L1Decay 实现 L1 权重衰减正则化,用于模型训练,使得权重矩 代码示例 1 :::::::::::: -.. code-block:: python - - # Example1: set Regularizer in optimizer - import paddle - from paddle.regularizer import L1Decay - import numpy as np - linear = paddle.nn.Linear(10, 10) - inp = paddle.rand(shape=[10, 10], dtype="float32") - out = linear(inp) - loss = paddle.mean(out) - beta1 = paddle.to_tensor([0.9], dtype="float32") - beta2 = paddle.to_tensor([0.99], dtype="float32") - momentum = paddle.optimizer.Momentum( - learning_rate=0.1, - parameters=linear.parameters(), - weight_decay=L1Decay(0.0001)) - back = out.backward() - momentum.step() - momentum.clear_grad() +COPY-FROM: paddle.regularizer.L1Decay:code-example1 代码示例 2 :::::::::::: -.. code-block:: python - - # Example2: set Regularizer in parameters - # Set L1 regularization in parameters. - # Global regularizer does not take effect on my_conv2d for this case. - from paddle.nn import Conv2D - from paddle import ParamAttr - from paddle.regularizer import L2Decay - - my_conv2d = Conv2D( - in_channels=10, - out_channels=10, - kernel_size=1, - stride=1, - padding=0, - weight_attr=ParamAttr(regularizer=L2Decay(coeff=0.01)), - bias_attr=False) +COPY-FROM: paddle.regularizer.L1Decay:code-example2 diff --git a/docs/api/paddle/regularizer/L2Decay_cn.rst b/docs/api/paddle/regularizer/L2Decay_cn.rst index d0fb55e305a..ea67ac573af 100644 --- a/docs/api/paddle/regularizer/L2Decay_cn.rst +++ b/docs/api/paddle/regularizer/L2Decay_cn.rst @@ -28,44 +28,10 @@ L2Decay 实现 L2 权重衰减正则化,用于模型训练,有助于防止 代码示例 1 :::::::::::: -.. code-block:: python - - # Example1: set Regularizer in optimizer - import paddle - from paddle.regularizer import L2Decay - import numpy as np - linear = paddle.nn.Linear(10, 10) - inp = paddle.rand(shape=[10, 10], dtype="float32") - out = linear(inp) - loss = paddle.mean(out) - beta1 = paddle.to_tensor([0.9], dtype="float32") - beta2 = paddle.to_tensor([0.99], dtype="float32") - momentum = paddle.optimizer.Momentum( - learning_rate=0.1, - parameters=linear.parameters(), - weight_decay=L2Decay(0.0001)) - back = out.backward() - momentum.step() - momentum.clear_grad() +COPY-FROM: paddle.regularizer.L2Decay:code-example1 代码示例 2 :::::::::::: -.. code-block:: python - - # Example2: set Regularizer in parameters - # Set L2 regularization in parameters. - # Global regularizer does not take effect on my_conv2d for this case. - from paddle.nn import Conv2D - from paddle import ParamAttr - from paddle.regularizer import L2Decay - - my_conv2d = Conv2D( - in_channels=10, - out_channels=10, - kernel_size=1, - stride=1, - padding=0, - weight_attr=ParamAttr(regularizer=L2Decay(coeff=0.01)), - bias_attr=False) +COPY-FROM: paddle.regularizer.L2Decay:code-example2