未验证 提交 7f320346 编写于 作者: L Li Fuchen 提交者: GitHub

modified the cn doc of scaled_dot_product_attention and add_position_encoding, test=develop (#1955)

上级 7e5d81be
......@@ -34,14 +34,13 @@ add_position_encoding
.. code-block:: python
import paddle.fluid as fluid
tensor = fluid.layers.data(
import paddle.fluid as fluid
tensor = fluid.data(
name='tensor',
shape=[32, 64, 512],
dtype='float32',
append_batch_size=False)
position_tensor = fluid.layers.add_position_encoding(
shape=[None, 64, 512],
dtype='float32')
position_tensor = fluid.layers.add_position_encoding(
input=tensor, alpha=1.0, beta=1.0)
......@@ -53,4 +52,3 @@ add_position_encoding
......@@ -43,31 +43,12 @@ scaled_dot_product_attention
.. code-block:: python
import paddle.fluid as fluid
queries = fluid.layers.data(name="queries",
shape=[3, 5, 9],
dtype="float32",
append_batch_size=False)
queries.stop_gradient = False
keys = fluid.layers.data(name="keys",
shape=[3, 6, 9],
dtype="float32",
append_batch_size=False)
keys.stop_gradient = False
values = fluid.layers.data(name="values",
shape=[3, 6, 10],
dtype="float32",
append_batch_size=False)
values.stop_gradient = False
contexts = fluid.nets.scaled_dot_product_attention(queries, keys, values)
contexts.shape # [3, 5, 10]
import paddle.fluid as fluid
queries = fluid.data(name="queries", shape=[3, 5, 9], dtype="float32")
keys = fluid.data(name="keys", shape=[3, 6, 9], dtype="float32")
values = fluid.data(name="values", shape=[3, 6, 10], dtype="float32")
contexts = fluid.nets.scaled_dot_product_attention(queries, keys, values)
contexts.shape # [3, 5, 10]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册