Skip to content
New issue

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

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

Already on GitHub? # to your account

修复 paddle.nn.functional.one_hot等 API 的文档 #58919

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions python/paddle/nn/functional/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
def one_hot(x, num_classes, name=None):
"""

The operator converts each id in the input 'x' to an one-hot vector with a
num_classes length. The value in the vector dimension corresponding to the id
The operator converts each id in the input `x` to an one-hot vector with a
`num_classes` length. The value in the vector dimension corresponding to the id
is 1, and the value in the remaining dimension is 0.

The shape of output Tensor is generated by appending num_classes dimension
behind the last dimension of the 'x' shape.
The shape of output Tensor is generated by appending `num_classes` dimension
behind the last dimension of the `x` shape.

.. code-block:: text

Expand Down Expand Up @@ -63,11 +63,14 @@ def one_hot(x, num_classes, name=None):
Args:
x(Tensor): Tensor with shape :math:`[N_1, N_2, ..., N_k]` ,
which contains at least one dimension. The data type is int32 or int64.
num_classes(int): An integer defining the num_classes of the one hot dimension. If input 'x'
is word id, num_classes is generally the dictionary size.
num_classes(int): An integer defining the `num_classes` of the one hot dimension. If input `x`
is word id, `num_classes` is generally the dictionary size.
name(str|None, optional): For detailed information, please refer
to :ref:`api_guide_Name`. Usually name is no need to set and
None by default.

Returns:
Tensor: The one-hot representations of 'x'. A Tensor with type float32.
Tensor: The one-hot representations of `x`. A Tensor with type float32.

Examples:
.. code-block:: python
Expand Down
4 changes: 1 addition & 3 deletions python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,9 +1527,7 @@ def flatten(x, start_axis=0, stop_axis=-1, name=None):
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
Tensor, A tensor with the contents of the input tensor, with input \
axes flattened by indicated start axis and end axis. \
A Tensor with data type same as input x.
Tensor, A tensor with the contents of the input tensor, whose input axes are flattened by indicated :attr:`start_axis` and :attr:`end_axis`, and data type is the same as input :attr:`x`.

Examples:

Expand Down
5 changes: 4 additions & 1 deletion python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,9 @@ def multiply(x, y, name=None):
out = x * y

Note:
Supported shape of :attr:`x` and :attr:`y` for this operator:
1. `x.shape` == `y.shape`.
2. `x.shape` could be the continuous subsequence of `y.shape`.
``paddle.multiply`` supports broadcasting. If you would like to know more about broadcasting, please refer to `Introduction to Tensor`_ .

.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Expand All @@ -1052,7 +1055,7 @@ def multiply(x, y, name=None):
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are "broadcastable", the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
N-D Tensor. A location into which the result is stored. If :attr:`x`, :attr:`y` have different shapes and are "broadcastable", the resulting tensor shape is the shape of :attr:`x` and :attr:`y` after broadcasting. If :attr:`x`, :attr:`y` have the same shape, its shape is the same as :attr:`x` and :attr:`y`.

Examples:

Expand Down
5 changes: 3 additions & 2 deletions python/paddle/vision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,13 @@ class ToTensor(BaseTransform):

.. code-block:: python

>>> import numpy as np
>>> from PIL import Image
>>> import paddle
>>> import paddle.vision.transforms as T
>>> import paddle.vision.transforms.functional as F

>>> fake_img = Image.fromarray((np.random.rand(4, 5, 3) * 255.).astype(np.uint8))
>>> img_arr = ((paddle.rand((4, 5, 3)) * 255.).astype('uint8')).numpy()
>>> fake_img = Image.fromarray(img_arr)
>>> transform = T.ToTensor()
>>> tensor = transform(fake_img)
>>> print(tensor.shape)
Expand Down