From 15453d05a8d4a4f96135545a4b4919ec0c82b4d2 Mon Sep 17 00:00:00 2001 From: Jiabin Yang Date: Fri, 17 May 2019 10:44:54 +0800 Subject: [PATCH] test=develop, fix AdgradOptimizer example code (#17401) --- python/paddle/fluid/optimizer.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index 21470bbef4d..5d9f7d1ee7d 100644 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -1006,8 +1006,22 @@ class AdagradOptimizer(Optimizer): Examples: .. code-block:: python + import paddle.fluid as fluid + import numpy as np + + np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32) + inp = fluid.layers.data( + name="inp", shape=[2, 2], append_batch_size=False) + out = fluid.layers.fc(inp, size=3) + out = fluid.layers.reduce_sum(out) optimizer = fluid.optimizer.Adagrad(learning_rate=0.2) - optimizer.minimize(cost) + optimizer.minimize(out) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + exe.run( + feed={"inp": np_inp}, + fetch_list=[out.name]) """ _moment_acc_str = "moment" -- GitLab