From a15af38a739090b3692201116c13fa114a84359a Mon Sep 17 00:00:00 2001 From: Li Fuchen Date: Fri, 25 Sep 2020 17:21:32 +0800 Subject: [PATCH] modified sample code of add_position_encoding to 2.0 (#2683) * add cn doc of trace API * modified sample code of add_position_encoding to 2.0 --- .../api_cn/layers_cn/add_position_encoding_cn.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/fluid/api_cn/layers_cn/add_position_encoding_cn.rst b/doc/fluid/api_cn/layers_cn/add_position_encoding_cn.rst index abba3377b..b6eda83b8 100644 --- a/doc/fluid/api_cn/layers_cn/add_position_encoding_cn.rst +++ b/doc/fluid/api_cn/layers_cn/add_position_encoding_cn.rst @@ -40,13 +40,13 @@ add_position_encoding .. code-block:: python - import paddle.fluid as fluid + import numpy as np + import paddle + import paddle.nn.functional as F - tensor = fluid.data( - name='tensor', - shape=[None, 64, 512], - dtype='float32') - position_tensor = fluid.layers.add_position_encoding( + tensor = np.random.randn(16, 32, 64) + tensor = paddle.to_tensor(tensor) + position_tensor = F.add_position_encoding( input=tensor, alpha=1.0, beta=1.0) -- GitLab