Skip to content
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

add categorical class #27695

Merged
merged 22 commits into from
Sep 30, 2020
Merged

add categorical class #27695

merged 22 commits into from
Sep 30, 2020

Conversation

pangyoki
Copy link
Contributor

@pangyoki pangyoki commented Sep 28, 2020

PR types

Others

PR changes

APIs

Describe

  • add Categorical class
    It's a special case of multinomial ( refer to PR add multinomial op #27219 ). Categorical distribution is a discrete probability distribution that describes the possible results of a random variable that can take on one of K possible categories, with the probability of each category separately specified.

  • add sample method
    Using multinomial to sample from Categorical distribution.

  • add probs and log_prob method
    Given category index, return the probability of this category.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

python/paddle/distribution.py Outdated Show resolved Hide resolved
python/paddle/distribution.py Outdated Show resolved Hide resolved
python/paddle/distribution.py Outdated Show resolved Hide resolved
python/paddle/distribution.py Outdated Show resolved Hide resolved
python/paddle/distribution.py Outdated Show resolved Hide resolved
@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Sep 30, 2020
@PaddlePaddle PaddlePaddle unlocked this conversation Sep 30, 2020
* :math:`[x=i]` : it evaluates to 1 if :math:`x==i` , 0 otherwise.

Args:
logits(list|numpy.ndarray|Tensor): The logits input of categorical distribution. The data type is float32 or float64.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add parameter name, will refine it in next PR.

Copy link
Contributor Author

@pangyoki pangyoki Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, refer to PR #27946

def __init__(self, logits, name=None):
"""
Args:
logits(list|numpy.ndarray|Variable): The logits input of categorical distribution. The data type is float32 or float64.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable change to Tensor, add parameter name, will refine it in next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, refer to PR #27946

other (Categorical): instance of Categorical. The data type is float32.

Returns:
Variable: kl-divergence between two Categorical distributions.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change Variable to Tensor, will refine it in next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, refer to PR #27946

"""Shannon entropy in nats.

Returns:
Variable: Shannon entropy of Categorical distribution. The data type is float32.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change Variable to Tensor, will refine it in next PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, refer to PR #27946

@zhiqiu zhiqiu self-requested a review September 30, 2020 06:21
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Tensor: A tensor with prepended dimensions shape.

Examples:
.. code-block:: python
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

``code-block:: python` needs indentation. The same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, refer to PR #27946

@zhiqiu zhiqiu merged commit 9b3ef59 into PaddlePaddle:develop Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants