From 9484567be527076f41cebb7112f10aa4d385c55a Mon Sep 17 00:00:00 2001 From: lfchener Date: Fri, 25 Sep 2020 06:59:15 +0000 Subject: [PATCH] modified sample code of add_position_encoding to 2.0, test=document_fix --- python/paddle/fluid/layers/nn.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 3e7d10f8d1a..774630e7ef5 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -13156,14 +13156,14 @@ def add_position_encoding(input, alpha, beta, name=None): Examples: .. 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( - input=tensor, alpha=1.0, beta=1.0) + 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) """ helper = LayerHelper('add_position_encoding', **locals()) -- GitLab