Skip to content

修复文档 paddle.nn.functional.embedding paddle.index_add #7250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix embedding
  • Loading branch information
cangtianhuang committed Apr 12, 2025
commit 0d72575c39d21a11b6d939f96b93793d24da3265
20 changes: 10 additions & 10 deletions docs/api/paddle/nn/functional/embedding_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ embedding



嵌入层(Embedding Layer),根据 input 中的 id 信息从 embedding 矩阵中查询对应 embedding 信息,并会根据输入的 size (vocab_size, emb_size)和 dtype 自动构造一个二维 embedding 矩阵。
嵌入层(Embedding Layer),根据输入 x 中的 id 信息从 embedding 矩阵中查询对应 embedding 信息,并会根据输入的 weight (num_embeddings, embedding_dim) 和 dtype 自动构造一个二维 embedding 矩阵。

输出的 Tensor 的 shape 是将输入 Tensor shape 后追加一维 emb_size
输出的 Tensor 的 shape 是将输入 Tensor shape 后追加一维 embedding_dim

.. note::

input 中的 id 必须满足 ``0 =< id < size[0]``,否则程序会抛异常退出
x 中的 id 必须满足 ``0 =< id < weight.shape[0]``,否则程序会抛出异常并退出


.. code-block:: text
Expand All @@ -39,19 +39,19 @@ embedding
::::::::::::


- **input** (Tensor) - 存储 id 信息的 Tensor,数据类型必须为:int32/int64。input 中的 id 必须满足 ``0 =< id < size[0]`` 。
- **weight** (Tensor) - 存储词嵌入权重参数的 Tensor,形状为(num_embeddings, embedding_dim)。
- **padding_idx** (int|long|None,可选) - padding_idx 的配置区间为 ``[-weight.shape[0], weight.shape[0]``,如果配置了 padding_idx,那么在训练过程中遇到此 id 时,其参数及对应的梯度将会以 0 进行填充。如果 padding_idx < 0 ,则 padding_idx 将自动转换到 ``weight.shape[0] + padding_idx`` 。如果设置为 "None",则不会对输出产生影响。默认值:None。
- **max_norm** (float,可选) - 若声明,会将范数大于此值的词嵌入向量重新归一化,使其范数等于此值。在动态图模式下会对 ``weight`` 产生 inplace 修改。默认值为 None。
- **norm_type** (float) - 应用 ``max_norm`` 时所计算的 p 阶范数的 p 值。默认值 2.0。
- **x** (Tensor) - 存储 id 信息的 Tensor,数据类型必须为:int32/int64。输入中的 id 必须满足 ``0 =< id < weight.shape[0]`` 。
- **weight** (Tensor) - 存储词嵌入权重参数的 Tensor,形状为 (num_embeddings, embedding_dim)
- **padding_idx** (int|None,可选) - padding_idx 的配置区间为 ``[-weight.shape[0], weight.shape[0])``,如果配置了 padding_idx,那么在训练过程中遇到此 id 时,其参数及对应的梯度将会以 0 进行填充。如果 padding_idx < 0 ,则 padding_idx 将自动转换到 ``weight.shape[0] + padding_idx`` 。如果设置为 None,则不会对输出产生影响。默认值:None。
- **max_norm** (float,可选) - 若声明,会将范数大于此值的词嵌入向量重新归一化,使其范数等于此值。在动态图模式下会对 ``weight`` 产生 inplace 修改。默认值:None。
- **norm_type** (float) - 应用 ``max_norm`` 时所计算的 p 阶范数的 p 值。默认值2.0。
- **sparse** (bool,可选) - 是否使用稀疏更新,在词嵌入权重较大的情况下,使用稀疏更新(即设置为 True)能够获得更快的训练速度及更小的内存/显存占用。但是一些优化器不支持稀疏更新,例如 :ref:`cn_api_paddle_optimizer_Adadelta` , :ref:`cn_api_paddle_optimizer_Adamax` , :ref:`cn_api_paddle_optimizer_Lamb` 。在这些情况下,稀疏必须为 False。默认值:False。
- **scale_grad_by_freq** (bool,可选) - 是否根据单词在 mini-batch 中出现频率的倒数缩放梯度。默认值 False。
- **scale_grad_by_freq** (bool,可选) - 是否根据单词在 mini-batch 中出现频率的倒数缩放梯度。默认值False。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。


返回
::::::::::::
Tensor, input 映射后得到的 Embedding Tensor,数据类型和权重定义的类型一致。
Tensor, x 映射后得到的 Embedding Tensor,数据类型和权重定义的类型一致。


代码示例
Expand Down