-
Notifications
You must be signed in to change notification settings - Fork 295
polynomial_autograd.py 추가 오탈자 수정 #1125
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
rlarbdus128-sys
wants to merge
2
commits into
PyTorchKR:master
Choose a base branch
from
rlarbdus128-sys:patch-5
base: master
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
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| PyTorch: 텐서(Tensor)와 autograd | ||
| PyTorch: Tensor와 autograd | ||
| ----------------------------------- | ||
|
|
||
| :math:`y=\sin(x)`를 예측할 수 있도록, :math:`-\pi`부터 :math:`\pi`까지 | ||
| 유클리드 거리(Euclidean distance)를 최소화하도록 3차 다항식을 학습합니다. | ||
|
|
||
| 이 구현은 PyTorch 텐서 연산을 사용하여 순전파 단계를 계산하고, PyTorch autograd를 사용하여 | ||
| 이 구현은 PyTorch Tensor 연산을 사용하여 순전파 단계를 계산하고, PyTorch autograd를 사용하여 | ||
| 변화도(gradient)를 계산합니다. | ||
|
|
||
| PyTorch 텐서는 연산 그래프에서 노드(node)로 표현됩니다. 만약 ``x``가 ``x.requires_grad=True``인 | ||
| 텐서라면, ``x.grad``는 어떤 스칼라 값에 대한 ``x``의 변화도를 갖는 또 다른 텐서입니다. | ||
| PyTorch Tensor는 연산 그래프에서 노드(node)로 표현됩니다. 만약 ``x`` 가 ``x.requires_grad=True`` 인 | ||
| Tensor라면, ``x.grad`` 는 어떤 스칼라 값에 대한 ``x`` 의 변화도를 갖는 또다른 Tensor입니다. | ||
| """ | ||
| import torch | ||
| import math | ||
|
|
@@ -19,15 +19,15 @@ | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | ||
| torch.set_default_device(device) | ||
|
|
||
| # 입력값과 출력값을 갖는 텐서들을 생성합니다. | ||
| # requires_grad=False가 기본값으로 설정되어 역전파 단계 중에 이 텐서들에 대한 변화도를 | ||
| # 입력값과 출력값을 갖는 Tensor들을 생성합니다. | ||
| # requires_grad=False가 기본값으로 설정되어 역전파 단계 중에 이 Tensor들에 대한 변화도를 | ||
| # 계산할 필요가 없음을 나타냅니다. | ||
| x = torch.linspace(-math.pi, math.pi, 2000, dtype=dtype) | ||
| y = torch.sin(x) | ||
|
|
||
| # 가중치를 갖는 임의의 텐서를 생성합니다. 3차 다항식이므로 4개의 가중치가 필요합니다: | ||
| # 가중치를 갖는 임의의 Tensor를 생성합니다. 3차 다항식이므로 4개의 가중치가 필요합니다: | ||
|
Member
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. : 대신 . 로 표현하는 게 더 자연스러울 것 같습니다. |
||
| # y = a + b x + c x^2 + d x^3 | ||
| # requires_grad=True로 설정하여 역전파 단계 중에 이 텐서들에 대한 변화도를 계산할 필요가 | ||
| # requires_grad=True로 설정하여 역전파 단계 중에 이 Tensor들에 대한 변화도를 계산할 필요가 | ||
| # 있음을 나타냅니다. | ||
| a = torch.randn((), dtype=dtype, requires_grad=True) | ||
| b = torch.randn((), dtype=dtype, requires_grad=True) | ||
|
|
@@ -36,20 +36,20 @@ | |
|
|
||
| learning_rate = 1e-6 | ||
| for t in range(2000): | ||
| # 순전파 단계: 텐서들 간의 연산을 사용하여 예측값 y를 계산합니다. | ||
| # 순전파 단계: Tensor들 간의 연산을 사용하여 예측값 y를 계산합니다. | ||
| y_pred = a + b * x + c * x ** 2 + d * x ** 3 | ||
|
|
||
| # 텐서들 간의 연산을 사용하여 손실(loss)을 계산하고 출력합니다. | ||
| # 이때 손실은 (1,) shape를 갖는 텐서입니다. | ||
| # loss.item()으로 손실이 갖고 있는 스칼라 값을 가져올 수 있습니다. | ||
| # Tensor들간의 연산을 사용하여 손실(loss)을 계산하고 출력합니다. | ||
| # 이 때 손실은 (1,) shape을 갖는 Tensor입니다. | ||
|
Member
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. 이때는 붙여 쓰는 것이 맞는 표기로, 수정 요청드립니다. |
||
| # loss.item() 으로 손실이 갖고 있는 스칼라 값을 가져올 수 있습니다. | ||
| loss = (y_pred - y).pow(2).sum() | ||
| if t % 100 == 99: | ||
| print(t, loss.item()) | ||
|
|
||
| # autograd 를 사용하여 역전파 단계를 계산합니다. 이는 requires_grad=True를 갖는 | ||
| # 모든 텐서들에 대한 손실의 변화도를 계산합니다. | ||
| # 모든 Tensor들에 대한 손실의 변화도를 계산합니다. | ||
| # 이후 a.grad와 b.grad, c.grad, d.grad는 각각 a, b, c, d에 대한 손실의 변화도를 | ||
| # 갖는 텐서가 됩니다. | ||
| # 갖는 Tensor가 됩니다. | ||
| loss.backward() | ||
|
|
||
| # 경사하강법(gradient descent)을 사용하여 가중치를 직접 갱신합니다. | ||
|
|
||
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.
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.
Tensor들 이라고 복수형으로 표현하는 것이 더 어색해 Tensor 라고만 표현해도 될 것 같습니다.
L39, 42, 50 등 모두 검토해주세요.