-
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
Open
aedpluto
wants to merge
6
commits into
Codecademy:main
Choose a base branch
from
aedpluto:new-sigmoid-description
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ba32fc
Add new description of sigmoid function in sigmoid.md
aedpluto 30dcd5a
Revise title and description for sigmoid function
mamtawardhani 59f15ba
Address maintainer feedback
aedpluto f5321db
Add example plot
aedpluto 256bcdb
Merge branch 'main' into new-sigmoid-description
aedpluto ff533f8
Merge branch 'main' into new-sigmoid-description
aedpluto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
content/pytorch/concepts/tensor-operations/terms/sigmoid/sigmoid.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| ``` | ||
aedpluto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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) | ||
| ``` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.