未验证 提交 8e631715 编写于 作者: N Nyakku Shigure 提交者: GitHub

fix paddle.optimizer.SGD en docs (#40479)

* align to cn docs

* add parameter `weight_decay`
上级 849bfbbf
...@@ -59,16 +59,14 @@ class SGD(Optimizer): ...@@ -59,16 +59,14 @@ class SGD(Optimizer):
.. code-block:: python .. code-block:: python
import paddle import paddle
import numpy as np
inp = np.random.uniform(-0.1, 0.1, [10, 10]).astype("float32") inp = paddle.uniform(min=-0.1, max=0.1, shape=[10, 10], dtype='float32')
linear = paddle.nn.Linear(10, 10) linear = paddle.nn.Linear(10, 10)
inp = paddle.to_tensor(inp) inp = paddle.to_tensor(inp)
out = linear(inp) out = linear(inp)
loss = paddle.mean(out) loss = paddle.mean(out)
beta1 = paddle.to_tensor([0.9], dtype="float32")
beta2 = paddle.to_tensor([0.99], dtype="float32")
sgd = paddle.optimizer.SGD(learning_rate=0.1, parameters=linear.parameters(), weight_decay=0.01) sgd = paddle.optimizer.SGD(learning_rate=0.1, parameters=linear.parameters(), weight_decay=0.01)
back = out.backward() out.backward()
sgd.step() sgd.step()
sgd.clear_grad() sgd.clear_grad()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册