-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[Term Entry] PyTorch Sigmoid Example #8105
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| Title: '.sigmoid()' | ||
| <<<<<<< HEAD | ||
| Description: 'The sigmoid function is an S-shaped curve typically used in binary classification problems' | ||
| ======= | ||
| Description: 'Applies the sigmoid activation to each element of a tensor, mapping values to a range between 0 and 1' | ||
| >>>>>>> c428da50f (Address maintainer feedback) | ||
| Subjects: | ||
| - 'AI' | ||
| - 'Machine Learning' | ||
| Tags: | ||
| - 'AI' | ||
| - 'Classification' | ||
| - 'Logistic Regression' | ||
| - 'Machine Learning' | ||
| - 'Math' | ||
| - 'Models' | ||
| - 'Neural Networks' | ||
| - 'Python' | ||
| - 'PyTorch' | ||
| CatalogContent: | ||
| - 'py-torch-for-classification' | ||
| - 'intro-to-py-torch-and-neural-networks' | ||
| --- | ||
|
|
||
| <<<<<<< HEAD | ||
| A **`.sigmoid()`** function is an S-shaped curve which maps any real-valued input to a bounded output, typically between 0 and 1. Sigmoid functions are regularly used as activation functions in non-linear classification problems, for example in neural networks, where the probability of a binary outcome is required. | ||
| ======= | ||
| The .sigmoid() function applies the sigmoid (logistic) function to each element of a tensor, producing an S-shaped curve that maps any real-valued input to a value between 0 and 1. | ||
| >>>>>>> c428da50f (Address maintainer feedback) | ||
|
|
||
| In machine learning, sigmoid is commonly used as an activation function in binary classification tasks, where outputs represent probabilities." | ||
|
|
||
| The formula for the sigmoid function is given by: | ||
| $$σ(x) = 1 / (1 + e^(-x))$$ | ||
|
|
||
| ## Example | ||
|
|
||
| The following example plots the sigmoid function: | ||
|
|
||
| ```py | ||
| import matplotlib.pyplot as plt | ||
| import torch | ||
|
|
||
| x = torch.linspace(-10, 10, steps=400) | ||
| y = torch.sigmoid(x) | ||
|
|
||
| plt.plot(x.numpy(), y.numpy()) | ||
| plt.title("Sigmoid function") | ||
| plt.xlabel("x") | ||
| plt.ylabel("σ(x)") | ||
| plt.show() | ||
| ``` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please attach the image of the output here, and I also suggest to add one more example that shows practical uses, example Applying .sigmoid() to a Tensor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| This example applies the sigmoid function to a tensor: | ||
|
|
||
| ```py | ||
| import torch | ||
|
|
||
| x = torch.tensor([-1.8, -1.5, 0.0, 2.0, 4.0]) | ||
| y = torch.sigmoid(x) | ||
|
|
||
| print(y) | ||
| ``` | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description should always start with a verb, and this description is slightly incorrect. A correct example description could be: "Applies the sigmoid activation to each element of a tensor, mapping values to a range between 0 and 1."