Skip to content

Commit 213a560

Browse files
committed
Rebuild
1 parent 53bb4ef commit 213a560

File tree

82 files changed

+278
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+278
-314
lines changed

โ€Ždocs/_downloads/6d8d81d44ebb8c150be6c39ce263fc89/torchtext_translation_tutorial.ipynb

Lines changed: 22 additions & 11 deletions
Large diffs are not rendered by default.

โ€Ždocs/_downloads/e733d8cec5d7c07a409a12a4273a4a28/torchtext_translation_tutorial.py

Lines changed: 57 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,48 @@
11
"""
2-
Language Translation with TorchText
2+
TorchText๋กœ ์–ธ์–ด ๋ฒˆ์—ญํ•˜๊ธฐ
33
===================================
44
5-
This tutorial shows how to use several convenience classes of ``torchtext`` to preprocess
6-
data from a well-known dataset containing sentences in both English and German and use it to
7-
train a sequence-to-sequence model with attention that can translate German sentences
8-
into English.
5+
์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ``torchtext`` ์˜ ์œ ์šฉํ•œ ์—ฌ๋Ÿฌ ํด๋ž˜์Šค๋“ค๊ณผ ์‹œํ€€์Šค ํˆฌ ์‹œํ€€์Šค(sequence-to-sequence, seq2seq)๋ชจ๋ธ์„ ํ†ตํ•ด
6+
์˜์–ด์™€ ๋…์ผ์–ด ๋ฌธ์žฅ๋“ค์ด ํฌํ•จ๋œ ์œ ๋ช…ํ•œ ๋ฐ์ดํ„ฐ ์…‹์„ ์ด์šฉํ•ด์„œ ๋…์ผ์–ด ๋ฌธ์žฅ์„ ์˜์–ด๋กœ ๋ฒˆ์—ญํ•ด ๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
97
10-
It is based off of
11-
`this tutorial <https://github.com/bentrevett/pytorch-seq2seq/blob/master/3%20-%20Neural%20Machine%20Translation%20by%20Jointly%20Learning%20to%20Align%20and%20Translate.ipynb>`__
12-
from PyTorch community member `Ben Trevett <https://github.com/bentrevett>`__
13-
and was created by `Seth Weidman <https://github.com/SethHWeidman/>`__ with Ben's permission.
8+
์ด ํŠœํ† ๋ฆฌ์–ผ์€
9+
PyTorch ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ฉค๋ฒ„์ธ `Ben Trevett <https://github.com/bentrevett>`__ ์ด ์ž‘์„ฑํ•œ
10+
`ํŠœํ† ๋ฆฌ์–ผ <https://github.com/bentrevett/pytorch-seq2seq/blob/master/3%20-%20Neural%20Machine%20Translation%20by%20Jointly%20Learning%20to%20Align%20and%20Translate.ipynb>`__ ์— ๊ธฐ์ดˆํ•˜๊ณ  ์žˆ์œผ๋ฉฐ
11+
`Seth Weidman <https://github.com/SethHWeidman/>`__ ์ด Ben์˜ ํ—ˆ๋ฝ์„ ๋ฐ›๊ณ  ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
1412
15-
By the end of this tutorial, you will be able to:
13+
์ด ํŠœํ† ๋ฆฌ์–ผ์„ ํ†ตํ•ด ์—ฌ๋Ÿฌ๋ถ„์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ์„ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค:
1614
17-
- Preprocess sentences into a commonly-used format for NLP modeling using the following ``torchtext`` convenience classes:
15+
- ``torchtext`` ์˜ ์•„๋ž˜์™€ ๊ฐ™์€ ์œ ์šฉํ•œ ํด๋ž˜์Šค๋“ค์„ ํ†ตํ•ด ๋ฌธ์žฅ๋“ค์„ NLP๋ชจ๋ธ๋ง์— ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ํ˜•ํƒœ๋กœ ์ „์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค:
1816
- `TranslationDataset <https://torchtext.readthedocs.io/en/latest/datasets.html#torchtext.datasets.TranslationDataset>`__
1917
- `Field <https://torchtext.readthedocs.io/en/latest/data.html#torchtext.data.Field>`__
2018
- `BucketIterator <https://torchtext.readthedocs.io/en/latest/data.html#torchtext.data.BucketIterator>`__
2119
"""
2220

2321
######################################################################
24-
# `Field` and `TranslationDataset`
22+
# `Field` ์™€ `TranslationDataset`
2523
# ----------------
26-
# ``torchtext`` has utilities for creating datasets that can be easily
27-
# iterated through for the purposes of creating a language translation
28-
# model. One key class is a
29-
# `Field <https://github.com/pytorch/text/blob/master/torchtext/data/field.py#L64>`__,
30-
# which specifies the way each sentence should be preprocessed, and another is the
31-
# `TranslationDataset` ; ``torchtext``
32-
# has several such datasets; in this tutorial we'll use the
33-
# `Multi30k dataset <https://github.com/multi30k/dataset>`__, which contains about
34-
# 30,000 sentences (averaging about 13 words in length) in both English and German.
24+
# ``torchtext`` ์—๋Š” ์–ธ์–ด ๋ณ€ํ™˜ ๋ชจ๋ธ์„ ๋งŒ๋“ค๋•Œ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ์…‹์„ ๋งŒ๋“ค๊ธฐ ์ ํ•ฉํ•œ ๋‹ค์–‘ํ•œ ๋„๊ตฌ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
25+
# ๊ทธ ์ค‘์—์„œ๋„ ์ค‘์š”ํ•œ ํด๋ž˜์Šค ์ค‘ ํ•˜๋‚˜์ธ `Field <https://github.com/pytorch/text/blob/master/torchtext/data/field.py#L64>`__ ๋Š”
26+
# ๊ฐ ๋ฌธ์žฅ์ด ์–ด๋–ป๊ฒŒ ์ „์ฒ˜๋ฆฌ๋˜์–ด์•ผ ํ•˜๋Š”์ง€ ์ง€์ •ํ•˜๋ฉฐ, ๋˜ ๋‹ค๋ฅธ ์ค‘์š”ํ•œ ํด๋ž˜์Šค๋กœ๋Š” `TranslationDataset` ์ด ์žˆ์Šต๋‹ˆ๋‹ค.
27+
# ``torchtext`` ์—๋Š” ์ด ์™ธ์—๋„ ๋น„์Šทํ•œ ๋ฐ์ดํ„ฐ์…‹๋“ค์ด ์žˆ๋Š”๋ฐ, ์ด๋ฒˆ ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” `Multi30k dataset <https://github.com/multi30k/dataset>`__ ์„ ์‚ฌ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
28+
# ์ด ๋ฐ์ดํ„ฐ ์…‹์€ ํ‰๊ท  ์•ฝ 13๊ฐœ์˜ ๋‹จ์–ด๋กœ ๊ตฌ์„ฑ๋œ ์•ฝ ์‚ผ๋งŒ ๊ฐœ์˜ ๋ฌธ์žฅ์„ ์˜์–ด์™€ ๋…์ผ์–ด ๋‘ ์–ธ์–ด๋กœ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
3529
#
36-
# Note: the tokenization in this tutorial requires `Spacy <https://spacy.io>`__
37-
# We use Spacy because it provides strong support for tokenization in languages
38-
# other than English. ``torchtext`` provides a ``basic_english`` tokenizer
39-
# and supports other tokenizers for English (e.g.
40-
# `Moses <https://bitbucket.org/luismsgomes/mosestokenizer/src/default/>`__)
41-
# but for language translation - where multiple languages are required -
42-
# Spacy is your best bet.
30+
# ์ฐธ๊ณ  : ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ์˜ ํ† ํฐํ™”(tokenization)์—๋Š” `Spacy <https://spacy.io>`__ ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
31+
# Spacy๋Š” ์˜์–ด ์ด ์™ธ์˜ ๋‹ค๋ฅธ ์–ธ์–ด์— ๋Œ€ํ•œ ๊ฐ•๋ ฅํ•œ ํ† ํฐํ™” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ``torchtext`` ๋Š”
32+
# `basic_english`` ํ† ํฌ๋‚˜์ด์ €๋ฅผ ์ œ๊ณตํ•  ๋ฟ ์•„๋‹ˆ๋ผ ์˜์–ด์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค๋ฅธ ํ† ํฌ๋‚˜์ด์ €๋“ค(์˜ˆ์ปจ๋ฐ
33+
# `Moses <https://bitbucket.org/luismsgomes/mosestokenizer/src/default/>`__ )์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค๋งŒ, ์–ธ์–ด ๋ฒˆ์—ญ์„ ์œ„ํ•ด์„œ๋Š” ๋‹ค์–‘ํ•œ ์–ธ์–ด๋ฅผ
34+
# ๋‹ค๋ฃจ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Spacy๊ฐ€ ๊ฐ€์žฅ ์ ํ•ฉํ•ฉ๋‹ˆ๋‹ค.
4335
#
44-
# To run this tutorial, first install ``spacy`` using ``pip`` or ``conda``.
45-
# Next, download the raw data for the English and German Spacy tokenizers:
36+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด, ์šฐ์„  ``pip`` ๋‚˜ ``conda`` ๋กœ ``spacy`` ๋ฅผ ์„ค์น˜ํ•˜์„ธ์š”. ๊ทธ ๋‹ค์Œ,
37+
# Spacy ํ† ํฌ๋‚˜์ด์ €๊ฐ€ ์“ธ ์˜์–ด์™€ ๋…์ผ์–ด์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์Šต๋‹ˆ๋‹ค.
4638
#
4739
# ::
4840
#
4941
# python -m spacy download en
5042
# python -m spacy download de
5143
#
52-
# With Spacy installed, the following code will tokenize each of the sentences
53-
# in the ``TranslationDataset`` based on the tokenizer defined in the ``Field``
54-
44+
# Spacy๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด, ๋‹ค์Œ ์ฝ”๋“œ๋Š” ``TranslationDataset`` ์— ์žˆ๋Š” ๊ฐ ๋ฌธ์žฅ์„ ``Field`` ์— ์ •์˜๋œ
45+
# ๋‚ด์šฉ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ํ† ํฐํ™”ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
5546
from torchtext.datasets import Multi30k
5647
from torchtext.data import Field, BucketIterator
5748

@@ -71,30 +62,24 @@
7162
fields = (SRC, TRG))
7263

7364
######################################################################
74-
# Now that we've defined ``train_data``, we can see an extremely useful
75-
# feature of ``torchtext``'s ``Field``: the ``build_vocab`` method
76-
# now allows us to create the vocabulary associated with each language
65+
# ์ด์ œ ``train_data`` ๋ฅผ ์ •์˜ํ–ˆ์œผ๋‹ˆ, ``torchtext`` ์˜ ``Field`` ์— ์žˆ๋Š” ์—„์ฒญ๋‚˜๊ฒŒ ์œ ์šฉํ•œ ๊ธฐ๋Šฅ์„
66+
# ๋ณด๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค : ๋ฐ”๋กœ ``build_vovab`` ๋ฉ”์†Œ๋“œ(method)๋กœ ๊ฐ ์–ธ์–ด์™€ ์—ฐ๊ด€๋œ ์–ดํœ˜๋“ค์„ ๋งŒ๋“ค์–ด ๋‚ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
7767

7868
SRC.build_vocab(train_data, min_freq = 2)
7969
TRG.build_vocab(train_data, min_freq = 2)
8070

8171
######################################################################
82-
# Once these lines of code have been run, ``SRC.vocab.stoi`` will be a
83-
# dictionary with the tokens in the vocabulary as keys and their
84-
# corresponding indices as values; ``SRC.vocab.itos`` will be the same
85-
# dictionary with the keys and values swapped. We won't make extensive
86-
# use of this fact in this tutorial, but this will likely be useful in
87-
# other NLP tasks you'll encounter.
72+
# ์œ„ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๋ฉด, ``SRC.vocab.stoi`` ๋Š” ์–ดํœ˜์— ํ•ด๋‹นํ•˜๋Š” ํ† ํฐ์„ ํ‚ค๋กœ, ๊ด€๋ จ๋œ ์ƒ‰์ธ์„ ๊ฐ’์œผ๋กœ ๊ฐ€์ง€๋Š”
73+
# ์‚ฌ์ „(dict)์ด ๋ฉ๋‹ˆ๋‹ค. ``SRC.vocab.itos`` ์—ญ์‹œ ์‚ฌ์ „(dict)์ด์ง€๋งŒ, ํ‚ค์™€ ๊ฐ’์ด ์„œ๋กœ ๋ฐ˜๋Œ€์ž…๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š”
74+
# ๊ทธ๋‹ค์ง€ ์ค‘์š”ํ•˜์ง€ ์•Š์€ ๋‚ด์šฉ์ด์ง€๋งŒ, ์ด๋Ÿฐ ํŠน์„ฑ์€ ๋‹ค๋ฅธ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ ๋“ฑ์—์„œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
8875

8976
######################################################################
9077
# ``BucketIterator``
9178
# ----------------
92-
# The last ``torchtext`` specific feature we'll use is the ``BucketIterator``,
93-
# which is easy to use since it takes a ``TranslationDataset`` as its
94-
# first argument. Specifically, as the docs say:
95-
# Defines an iterator that batches examples of similar lengths together.
96-
# Minimizes amount of padding needed while producing freshly shuffled
97-
# batches for each new epoch. See pool for the bucketing procedure used.
79+
# ๋งˆ์ง€๋ง‰์œผ๋กœ ์‚ฌ์šฉํ•ด ๋ณผ ``torchtext`` ์— ํŠนํ™”๋œ ๊ธฐ๋Šฅ์€ ๋ฐ”๋กœ ``BucketIterator`` ์ž…๋‹ˆ๋‹ค.
80+
# ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋กœ ``TranslationDataset`` ์„ ์ „๋‹ฌ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜๊ธฐ๊ฐ€ ์‰ฝ์Šต๋‹ˆ๋‹ค. ๋ฌธ์„œ์—์„œ๋„ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ
81+
# ์ด ๊ธฐ๋Šฅ์€ ๋น„์Šทํ•œ ๊ธธ์ด์˜ ์˜ˆ์ œ๋“ค์„ ๋ฌถ์–ด์ฃผ๋Š” ๋ฐ˜๋ณต์ž(iterator)๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ ์ƒˆ๋กœ์šด ์—ํฌํฌ(epoch)๋งˆ๋‹ค
82+
# ์ƒˆ๋กœ ์„ž์ธ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ ํ•„์š”ํ•œ ํŒจ๋”ฉ์˜ ์ˆ˜๋ฅผ ์ตœ์†Œํ™” ํ•ฉ๋‹ˆ๋‹ค. ๋ฒ„์ผ€ํŒ… ๊ณผ์ •์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ €์žฅ ๊ณต๊ฐ„์„ ํ•œ๋ฒˆ ์‚ดํŽด๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
9883

9984
import torch
10085

@@ -108,40 +93,36 @@
10893
device = device)
10994

11095
######################################################################
111-
# These iterators can be called just like ``DataLoader``s; below, in
112-
# the ``train`` and ``evaluate`` functions, they are called simply with:
113-
#
96+
# ์ด ๋ฐ˜๋ณต์ž๋“ค์€ ``DataLoader`` ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ``train`` ๊ณผ
97+
# ``evaluation`` ํ•จ์ˆ˜์—์„œ ๋ณด๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐ„๋‹จํžˆ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :
11498
# ::
11599
#
116100
# for i, batch in enumerate(iterator):
117101
#
118-
# Each ``batch`` then has ``src`` and ``trg`` attributes:
102+
# ๊ฐ ``batch`` ๋Š” ``src`` ์™€ ``trg`` ์†์„ฑ์„ ๊ฐ€์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
119103
#
120104
# ::
121105
#
122106
# src = batch.src
123107
# trg = batch.trg
124108

125109
######################################################################
126-
# Defining our ``nn.Module`` and ``Optimizer``
110+
# ``nn.Module`` ๊ณผ ``Optimizer`` ์ •์˜ํ•˜๊ธฐ
127111
# ----------------
128-
# That's mostly it from a ``torchtext`` perspecive: with the dataset built
129-
# and the iterator defined, the rest of this tutorial simply defines our
130-
# model as an ``nn.Module``, along with an ``Optimizer``, and then trains it.
112+
# ๋Œ€๋ถ€๋ถ„์€ ``torchtext`` ๊ฐ€ ์•Œ์•„์„œ ํ•ด์ค๋‹ˆ๋‹ค : ๋ฐ์ดํ„ฐ์…‹์ด ๋งŒ๋“ค์–ด์ง€๊ณ  ๋ฐ˜๋ณต์ž๊ฐ€ ์ •์˜๋˜๋ฉด, ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ
113+
# ์šฐ๋ฆฌ๊ฐ€ ํ•ด์•ผ ํ•  ์ผ์ด๋ผ๊ณ ๋Š” ๊ทธ์ € ``nn.Module`` ์™€ ``Optimizer`` ๋ฅผ ๋ชจ๋ธ๋กœ์„œ ์ •์˜ํ•˜๊ณ  ํ›ˆ๋ จ์‹œํ‚ค๋Š” ๊ฒƒ์ด ์ „๋ถ€์ž…๋‹ˆ๋‹ค.
114+
#
131115
#
132-
# Our model specifically, follows the architecture described
133-
# `here <https://arxiv.org/abs/1409.0473>`__ (you can find a
134-
# significantly more commented version
135-
# `here <https://github.com/SethHWeidman/pytorch-seq2seq/blob/master/3%20-%20Neural%20Machine%20Translation%20by%20Jointly%20Learning%20to%20Align%20and%20Translate.ipynb>`__).
136-
#
137-
# Note: this model is just an example model that can be used for language
138-
# translation; we choose it because it is a standard model for the task,
139-
# not because it is the recommended model to use for translation. As you're
140-
# likely aware, state-of-the-art models are currently based on Transformers;
141-
# you can see PyTorch's capabilities for implementing Transformer layers
142-
# `here <https://pytorch.org/docs/stable/nn.html#transformer-layers>`__; and
143-
# in particular, the "attention" used in the model below is different from
144-
# the multi-headed self-attention present in a transformer model.
116+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ ์‚ฌ์šฉํ•  ๋ชจ๋ธ์€ `์ด๊ณณ <https://arxiv.org/abs/1409.0473>`__ ์—์„œ ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋Š” ๊ตฌ์กฐ๋ฅผ ๋”ฐ๋ฅด๊ณ  ์žˆ์œผ๋ฉฐ,
117+
# ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ `์—ฌ๊ธฐ <https://github.com/SethHWeidman/pytorch-seq2seq/blob/master/3%20-%20Neural%20Machine%20Translation%20by%20Jointly%20Learning%20to%20Align%20and%20Translate.ipynb>`__
118+
# ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
119+
#
120+
# ์ฐธ๊ณ  : ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋ธ์€ ์–ธ์–ด ๋ฒˆ์—ญ์„ ์œ„ํ•ด ์‚ฌ์šฉํ•  ์˜ˆ์‹œ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค. ์ด ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€
121+
# ์ด ์ž‘์—…์— ์ ๋‹นํ•œ ํ‘œ์ค€ ๋ชจ๋ธ์ด๊ธฐ ๋•Œ๋ฌธ์ด์ง€, ๋ฒˆ์—ญ์— ์ ํ•ฉํ•œ ๋ชจ๋ธ์ด๊ธฐ ๋•Œ๋ฌธ์€ ์•„๋‹™๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์ด ์ตœ์‹  ๊ธฐ์ˆ  ํŠธ๋ Œ๋“œ๋ฅผ
122+
# ์ž˜ ๋”ฐ๋ผ๊ฐ€๊ณ  ์žˆ๋‹ค๋ฉด ์ž˜ ์•„์‹œ๊ฒ ์ง€๋งŒ, ํ˜„์žฌ ๋ฒˆ์—ญ์—์„œ ๊ฐ€์žฅ ๋›ฐ์–ด๋‚œ ๋ชจ๋ธ์€ Transformers์ž…๋‹ˆ๋‹ค. PyTorch๊ฐ€
123+
# Transformer ๋ ˆ์ด์–ด๋ฅผ ๊ตฌํ˜„ํ•œ ๋‚ด์šฉ์€ `์—ฌ๊ธฐ <https://pytorch.org/docs/stable/nn.html#transformer-layers>`__
124+
# ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ด ํŠœํ† ๋ฆฌ์–ผ์˜ ๋ชจ๋ธ์ด ์‚ฌ์šฉํ•˜๋Š” "attention" ์€ Transformer ๋ชจ๋ธ์—์„œ ์ œ์•ˆํ•˜๋Š”
125+
# ๋ฉ€ํ‹ฐ ํ—ค๋“œ ์…€ํ”„ ์–ดํ…์…˜(multi-headed self-attention) ๊ณผ๋Š” ๋‹ค๋ฅด๋‹ค๋Š” ์ ์„ ์•Œ๋ ค๋“œ๋ฆฝ๋‹ˆ๋‹ค.
145126

146127

147128
import random
@@ -316,7 +297,7 @@ def forward(self,
316297

317298
encoder_outputs, hidden = self.encoder(src)
318299

319-
# first input to the decoder is the <sos> token
300+
# ๋””์ฝ”๋”๋กœ์˜ ์ฒซ ๋ฒˆ์งธ ์ž…๋ ฅ์€ <sos> ํ† ํฐ์ž…๋‹ˆ๋‹ค.
320301
output = trg[0,:]
321302

322303
for t in range(1, max_len):
@@ -376,16 +357,15 @@ def count_parameters(model: nn.Module):
376357
print(f'The model has {count_parameters(model):,} trainable parameters')
377358

378359
######################################################################
379-
# Note: when scoring the performance of a language translation model in
380-
# particular, we have to tell the ``nn.CrossEntropyLoss`` function to
381-
# ignore the indices where the target is simply padding.
360+
# ์ฐธ๊ณ  : ์–ธ์–ด ๋ฒˆ์—ญ์˜ ์„ฑ๋Šฅ ์ ์ˆ˜๋ฅผ ๊ธฐ๋กํ•˜๋ ค๋ฉด, ``nn.CrossEntropyLoss`` ํ•จ์ˆ˜๊ฐ€ ๋‹จ์ˆœํ•œ
361+
# ํŒจ๋”ฉ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„์„ ๋ฌด์‹œํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด๋‹น ์ƒ‰์ธ๋“ค์„ ์•Œ๋ ค์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.
382362

383363
PAD_IDX = TRG.vocab.stoi['<pad>']
384364

385365
criterion = nn.CrossEntropyLoss(ignore_index=PAD_IDX)
386366

387367
######################################################################
388-
# Finally, we can train and evaluate this model:
368+
# ๋งˆ์ง€๋ง‰์œผ๋กœ ์ด ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•˜๊ณ  ํ‰๊ฐ€ํ•ฉ๋‹ˆ๋‹ค :
389369

390370
import math
391371
import time
@@ -486,11 +466,8 @@ def epoch_time(start_time: int,
486466
print(f'| Test Loss: {test_loss:.3f} | Test PPL: {math.exp(test_loss):7.3f} |')
487467

488468
######################################################################
489-
# Next steps
469+
# ๋‹ค์Œ ๋‹จ๊ณ„
490470
# --------------
491471
#
492-
# - Check out the rest of Ben Trevett's tutorials using ``torchtext``
493-
# `here <https://github.com/bentrevett/>`__
494-
# - Stay tuned for a tutorial using other ``torchtext`` features along
495-
# with ``nn.Transformer`` for language modeling via next word prediction!
496-
#
472+
# - ``torchtext`` ๋ฅผ ์‚ฌ์šฉํ•œ Ben Trevett์˜ ํŠœํ† ๋ฆฌ์–ผ์„ `์ด๊ณณ <https://github.com/bentrevett/>`__ ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
473+
# - ``nn.Transformer`` ์™€ ``torchtext`` ์˜ ๋‹ค๋ฅธ ๊ธฐ๋Šฅ๋“ค์„ ์ด์šฉํ•œ ๋‹ค์Œ ๋‹จ์–ด ์˜ˆ์ธก์„ ํ†ตํ•œ ์–ธ์–ด ๋ชจ๋ธ๋ง ํŠœํ† ๋ฆฌ์–ผ์„ ์‚ดํŽด๋ณด์„ธ์š”.

โ€Ždocs/_sources/index.rst.txt

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,24 @@ PyTorch๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด ์‹œ์ž‘ํ•˜๊ธฐ(Getting Start
66
์‹ ๊ฒฝ๋ง(deep neural network)์„ ๊ตฌ์ถ•ํ•  ๋•Œ PyTorch๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€์— ๋Œ€ํ•œ
77
์ „๋ฐ˜์ ์ธ ๋‚ด์šฉ์„ ๊ธฐ๋ณธ๋ถ€ํ„ฐ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
88

9-
(์—ญ์ž ์ฃผ: ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ์— ๋Œ€ํ•œ ์˜คํƒ€๋‚˜ ์˜ค์—ญ์„ ๋ฐœ๊ฒฌํ•˜์‹œ๋ฉด
10-
`๋ฒˆ์—ญ ์ €์žฅ์†Œ <https://github.com/9bow/PyTorch-tutorials-kr>`__ ์—
11-
`์ด์Šˆ <https://github.com/9bow/PyTorch-tutorials-kr/issues/new>`__ ๋˜๋Š”
12-
`PR <https://github.com/9bow/PyTorch-tutorials-kr/pulls>`__ ์„ ๋‚จ๊ฒจ์ฃผ์„ธ์š”.)
13-
14-
Some considerations:
15-
16-
* Weโ€™ve added a new feature to tutorials that allows users to open the notebook associated with a tutorial in Google Colab.
17-
Visit `this page <https://pytorch.org/tutorials/beginner/colab.html>`_ for more information.
18-
* If you would like to do the tutorials interactively via IPython / Jupyter,
19-
each tutorial has a download link for a Jupyter Notebook and Python source code.
20-
* Additional high-quality examples are available, including image classification,
21-
unsupervised learning, reinforcement learning, machine translation, and
22-
many other applications, in `PyTorch Examples
23-
<https://github.com/pytorch/examples/>`_.
24-
* You can find reference documentation for the PyTorch API and layers in `PyTorch Docs
25-
<https://pytorch.org/docs>`_ or via inline help.
26-
* If you would like the tutorials section improved, please open a github issue
27-
`here <https://github.com/pytorch/tutorials>`_ with your feedback.
28-
* Check out our
29-
`PyTorch Cheat Sheet <https://pytorch.org/tutorials/beginner/ptcheat.html>`_
30-
for additional useful information.
31-
* Finally, here's a link to the
32-
`PyTorch Release Notes <https://github.com/pytorch/pytorch/releases>`_
9+
์•„๋ž˜ ๋‚ด์šฉ๋„ ํ•œ ๋ฒˆ ์‚ดํŽด๋ณด์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค:
10+
11+
* ์‚ฌ์šฉ์ž๋“ค์ด ํŠœํ† ๋ฆฌ์–ผ๊ณผ ์—ฐ๊ด€๋œ ๋…ธํŠธ๋ถ์„ Google Colab์—์„œ ์—ด์–ด๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
12+
`์ด ํŽ˜์ด์ง€ <https://tutorials.pytorch.kr/beginner/colab.html>`_ ๋ฅผ ๋ฐฉ๋ฌธํ•˜์…”์„œ ์ž์„ธํžˆ ์•Œ์•„๋ณด์„ธ์š”!
13+
* ๊ฐ ํŠœํ† ๋ฆฌ์–ผ์—๋Š” Jupyter ๋…ธํŠธ๋ถ๊ณผ Python ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋Š” ๋งํฌ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
14+
IPython ๋˜๋Š” Jupyter๋ฅผ ์ด์šฉํ•˜์—ฌ ๋Œ€ํ™”์‹์œผ๋กœ ์‹คํ–‰ํ•˜์‹œ๋ ค๋ฉด ์ด์šฉํ•ด๋ณด์„ธ์š”.
15+
* ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜, ๋น„์ง€๋„ ํ•™์Šต, ๊ฐ•ํ™” ํ•™์Šต, ๊ธฐ๊ณ„ ๋ฒˆ์—ญ์„ ๋น„๋กฏํ•œ ๋‹ค์–‘ํ•œ ๊ณ ํ’ˆ์งˆ์˜ ์˜ˆ์ œ๊ฐ€
16+
`PyTorch Examples <https://github.com/pytorch/examples/>`_ ์— ์ค€๋น„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
17+
* PyTorch API, ๊ณ„์ธต(layer)์— ๋Œ€ํ•œ ์ฐธ๊ณ  ๋ฌธ์„œ๋Š” `PyTorch Docs <https://pytorch.org/docs>`_ ๋ฅผ
18+
์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.
19+
* ํŠœํ† ๋ฆฌ์–ผ ๊ฐœ์„ ์— ์ฐธ์—ฌํ•˜์‹œ๋ ค๋ฉด `์ด๊ณณ <https://github.com/pytorch/tutorials>`_ ์— ์˜๊ฒฌ๊ณผ ํ•จ๊ป˜
20+
์ด์Šˆ๋ฅผ ๋‚จ๊ฒจ์ฃผ์„ธ์š”.
21+
(์—ญ์ž ์ฃผ: ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ๊ณผ ๊ด€๋ จํ•œ ์˜คํƒ€ ๋ฐ ์˜ค์—ญ ๋“ฑ์€
22+
`ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ ์ €์žฅ์†Œ <https://github.com/9bow/PyTorch-tutorials-kr>`_ ์— ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.)
23+
* `PyTorch ์น˜ํŠธ ์‹œํŠธ(Cheat Sheet) <https://tutorials.pytorch.kr/beginner/ptcheat.html>`_ ๋ฅผ
24+
์ฐธ๊ณ ํ•˜์‹œ๋ฉด ์œ ์šฉํ•œ ์ •๋ณด๋“ค์„ ์–ป์œผ์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
25+
* ๋งˆ์ง€๋ง‰์œผ๋กœ `PyTorch ๋ฆด๋ฆฌ์ฆˆ ๋…ธํŠธ(Release Notes) <https://github.com/pytorch/pytorch/releases>`_
26+
๋„ ์ฐธ๊ณ ํ•ด๋ณด์„ธ์š”.
3327

3428
์‹œ์ž‘ํ•˜๊ธฐ (Getting Started)
3529
---------------------------
@@ -407,4 +401,4 @@ PyTorch Fundamentals In-Depth
407401
:caption: PyTorch Fundamentals In-Depth
408402

409403
beginner/pytorch_with_examples
410-
beginner/nn_tutorial
404+
beginner/nn_tutorial

โ€Ždocs/advanced/ONNXLive.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
<li class="toctree-l1"><a class="reference internal" href="../intermediate/char_rnn_generation_tutorial.html">๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” NLP: ๋ฌธ์ž-๋‹จ์œ„ RNN์œผ๋กœ ์ด๋ฆ„ ์ƒ์„ฑํ•˜๊ธฐ</a></li>
161161
<li class="toctree-l1"><a class="reference internal" href="../intermediate/seq2seq_translation_tutorial.html">๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” NLP: Sequence to Sequence ๋„คํŠธ์›Œํฌ์™€ Attention์„ ์ด์šฉํ•œ ๋ฒˆ์—ญ</a></li>
162162
<li class="toctree-l1"><a class="reference internal" href="../beginner/text_sentiment_ngrams_tutorial.html">Text Classification with TorchText</a></li>
163-
<li class="toctree-l1"><a class="reference internal" href="../beginner/torchtext_translation_tutorial.html">Language Translation with TorchText</a></li>
163+
<li class="toctree-l1"><a class="reference internal" href="../beginner/torchtext_translation_tutorial.html">TorchText๋กœ ์–ธ์–ด ๋ฒˆ์—ญํ•˜๊ธฐ</a></li>
164164
<li class="toctree-l1"><a class="reference internal" href="../beginner/transformer_tutorial.html">Sequence-to-Sequence Modeling with nn.Transformer and TorchText</a></li>
165165
</ul>
166166
<p class="caption"><span class="caption-text">Named Tensor (experimental)</span></p>

โ€Ždocs/advanced/cpp_export.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<li class="toctree-l1"><a class="reference internal" href="../intermediate/char_rnn_generation_tutorial.html">๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” NLP: ๋ฌธ์ž-๋‹จ์œ„ RNN์œผ๋กœ ์ด๋ฆ„ ์ƒ์„ฑํ•˜๊ธฐ</a></li>
163163
<li class="toctree-l1"><a class="reference internal" href="../intermediate/seq2seq_translation_tutorial.html">๊ธฐ์ดˆ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” NLP: Sequence to Sequence ๋„คํŠธ์›Œํฌ์™€ Attention์„ ์ด์šฉํ•œ ๋ฒˆ์—ญ</a></li>
164164
<li class="toctree-l1"><a class="reference internal" href="../beginner/text_sentiment_ngrams_tutorial.html">Text Classification with TorchText</a></li>
165-
<li class="toctree-l1"><a class="reference internal" href="../beginner/torchtext_translation_tutorial.html">Language Translation with TorchText</a></li>
165+
<li class="toctree-l1"><a class="reference internal" href="../beginner/torchtext_translation_tutorial.html">TorchText๋กœ ์–ธ์–ด ๋ฒˆ์—ญํ•˜๊ธฐ</a></li>
166166
<li class="toctree-l1"><a class="reference internal" href="../beginner/transformer_tutorial.html">Sequence-to-Sequence Modeling with nn.Transformer and TorchText</a></li>
167167
</ul>
168168
<p class="caption"><span class="caption-text">Named Tensor (experimental)</span></p>

0 commit comments

Comments
ย (0)