Skip to content

Commit

Permalink
修复 paddle.nn.functional.one_hot等 API 的文档 (PaddlePaddle#58919)
Browse files Browse the repository at this point in the history
* fix docs

* fix docs
  • Loading branch information
NKNaN authored Nov 14, 2023
1 parent 4c19b77 commit 6ba6398
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
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 @@ -1591,9 +1591,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 @@ -1055,6 +1055,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 @@ -1065,7 +1068,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

0 comments on commit 6ba6398

Please sign in to comment.