René's URL Explorer Experiment


Title: 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 생성하기 — 파이토치 한국어 튜토리얼 (PyTorch tutorials in Korean)

Open Graph Title: 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 생성하기

Description: Author: Sean Robertson, 번역: 황성수,. 이 튜토리얼은 3부로 구성된 시리즈의 일부입니다: 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기, 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 생성하기, 기초부터 시작하는 NLP: Sequence to Sequence 네트워크와 Attention을 이용한 번역. 이 튜토리얼은 3개로 이뤄진 “기초부터 시작하는 NLP”의 2번째 튜토리얼입니다. 첫번째 튜토리얼인 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기 에서는 RNN을 사용...

Open Graph Description: Author: Sean Robertson, 번역: 황성수,. 이 튜토리얼은 3부로 구성된 시리즈의 일부입니다: 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기, 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 생성하기, 기초부터 시작하는 NLP: Sequence to Sequence 네트워크와 Attention을 이용한 번역. 이 튜토리얼은 3개로 이뤄진 “기초부터 시작하는 NLP”의 2번째 튜토리얼입니다. 첫번째 튜토리얼인 기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기 에서는 RNN을 사용...

Opengraph URL: https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html

direct link

Domain: tutorials.pytorch.kr


Hey, it has json ld scripts:
    {
       "@context": "https://schema.org",
       "@type": "Article",
       "name": "\uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \uc0dd\uc131\ud558\uae30",
       "headline": "\uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \uc0dd\uc131\ud558\uae30",
       "description": "PyTorch Documentation. Explore PyTorch, an open-source machine learning library that accelerates the path from research prototyping to production deployment. Discover tutorials, API references, and guides to help you build and deploy deep learning models efficiently.",
       "url": "/intermediate/char_rnn_generation_tutorial.html",
       "articleBody": "\ucc38\uace0 Go to the end to download the full example code. \uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \uc0dd\uc131\ud558\uae30# Author: Sean Robertson\ubc88\uc5ed: \ud669\uc131\uc218 \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc740 3\ubd80\ub85c \uad6c\uc131\ub41c \uc2dc\ub9ac\uc988\uc758 \uc77c\ubd80\uc785\ub2c8\ub2e4: \uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \ubd84\ub958\ud558\uae30 \uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \uc0dd\uc131\ud558\uae30 \uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: Sequence to Sequence \ub124\ud2b8\uc6cc\ud06c\uc640 Attention\uc744 \uc774\uc6a9\ud55c \ubc88\uc5ed \uc774 \ud29c\ud1a0\ub9ac\uc5bc\uc740 3\uac1c\ub85c \uc774\ub904\uc9c4 \u201c\uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP\u201d\uc758 2\ubc88\uc9f8 \ud29c\ud1a0\ub9ac\uc5bc\uc785\ub2c8\ub2e4. \uccab\ubc88\uc9f8 \ud29c\ud1a0\ub9ac\uc5bc\uc778 \uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \ubd84\ub958\ud558\uae30 \uc5d0\uc11c\ub294 RNN\uc744 \uc0ac\uc6a9\ud558\uc5ec \uc8fc\uc5b4\uc9c4 \uc774\ub984\uc774 \uc5b4\ub5a0\ud55c \uc5b8\uc5b4\uc778\uc9c0\ub97c \ubd84\ub958\ud588\uc2b5\ub2c8\ub2e4. \uc774\ubc88\uc5d0\ub294 \ubc18\ub300\ub85c \uc5b8\uc5b4\ub85c\ubd80\ud130 \uc774\ub984\uc744 \uc0dd\uc131\ud560 \uc608\uc815\uc785\ub2c8\ub2e4. \u003e python sample.py Russian RUS Rovakov Uantov Shavakov \u003e python sample.py German GER Gerren Ereng Rosher \u003e python sample.py Spanish SPA Salla Parer Allan \u003e python sample.py Chinese CHI Chan Hang Iun \uc6b0\ub9ac\ub294 \uba87 \uac1c\uc758 \uc120\ud615 \uacc4\uce35\uc73c\ub85c \uc791\uc740 RNN\uc744 \uc9c1\uc811 \ub9cc\ub4e4\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\uc778 \uc774\ub984\uc744 \uc77d\uc740 \ud6c4 \uadf8 \uc5b8\uc5b4\ub97c \uc608\uce21\ud558\ub294 \uac83\uacfc\uc758 \ud070 \ucc28\uc774\uc810\uc740 \uc5b8\uc5b4\ub97c \uc785\ub825\ud558\uace0 \ud55c \ubc88\uc5d0 \ud55c \uae00\uc790\ub97c \uc0dd\uc131\ud558\uc5ec \ucd9c\ub825\ud558\ub294 \uac83\uc785\ub2c8\ub2e4. \uc5b8\uc5b4 \ud615\uc131(\ub2e8\uc5b4 \ub610\ub294 \ub2e4\ub978 \uace0\ucc28\uc6d0 \uad6c\uc870\ub85c\ub3c4 \uc218\ud589\ub420 \uc218 \uc788\uc74c)\uc744 \uc704\ud574 \ubb38\uc790\ub97c \ubc18\ubcf5\uc801\uc73c\ub85c \uc608\uce21\ud558\ub294 \uac83\uc744 \u201c\uc5b8\uc5b4 \ubaa8\ub378\u201d \uc774\ub77c\uace0 \ud569\ub2c8\ub2e4. \ucd94\ucc9c \uc790\ub8cc: Pytorch\ub97c \uc124\uce58\ud588\uace0, Python\uc744 \uc54c\uace0, Tensor\ub97c \uc774\ud574\ud55c\ub2e4\uace0 \uac00\uc815\ud569\ub2c8\ub2e4: https://pytorch.org/ \uc124\uce58 \uc548\ub0b4 PyTorch\ub85c \ub525\ub7ec\ub2dd\ud558\uae30: 60\ubd84\ub9cc\uc5d0 \ub05d\uc7a5\ub0b4\uae30 PyTorch \uc2dc\uc791\ud558\uae30 \uc608\uc81c\ub85c \ubc30\uc6b0\ub294 \ud30c\uc774\ud1a0\uce58(PyTorch) \ub113\uace0 \uae4a\uc740 \ud1b5\ucc30\uc744 \uc704\ud55c \uc790\ub8cc Torch \uc0ac\uc6a9\uc790\ub97c \uc704\ud55c PyTorch \uc774\uc804 Lua Torch \uc0ac\uc6a9\uc790\ub97c \uc704\ud55c \uc790\ub8cc RNN\uacfc \uc791\ub3d9 \ubc29\uc2dd\uc744 \uc544\ub294 \uac83 \ub610\ud55c \uc720\uc6a9\ud569\ub2c8\ub2e4: The Unreasonable Effectiveness of Recurrent Neural Networks \uc2e4\uc0dd\ud65c \uc608\uc81c\ub97c \ubcf4\uc5ec \uc90d\ub2c8\ub2e4. Understanding LSTM Networks LSTM\uc5d0 \uad00\ud55c \uac83\uc774\uc9c0\ub9cc RNN\uc5d0 \uad00\ud574\uc11c\ub3c4 \uc720\uc775\ud569\ub2c8\ub2e4. \uc774\uc804 \ud29c\ud1a0\ub9ac\uc5bc\ub3c4 \ucd94\ucc9c\ud569\ub2c8\ub2e4. \uae30\ucd08\ubd80\ud130 \uc2dc\uc791\ud558\ub294 NLP: \ubb38\uc790-\ub2e8\uc704 RNN\uc73c\ub85c \uc774\ub984 \ubd84\ub958\ud558\uae30 \ub370\uc774\ud130 \uc900\ube44# \ucc38\uace0 \uc5ec\uae30 \uc5d0\uc11c \ub370\uc774\ud130\ub97c \ub2e4\uc6b4 \ubc1b\uace0, \ud604\uc7ac \ub514\ub809\ud1a0\ub9ac\uc5d0 \uc555\ucd95\uc744 \ud478\uc2ed\uc2dc\uc624. \uc774 \uacfc\uc815\uc758 \ub354 \uc790\uc138\ud55c \uc0ac\ud56d\uc740 \uc9c0\ub09c \ud29c\ud1a0\ub9ac\uc5bc\uc744 \ubcf4\uc2ed\uc2dc\uc624. \uc694\uc57d\ud558\uba74, \uc904\ub9c8\ub2e4 \uc774\ub984\uc774 \uc801\ud78c \ud14d\uc2a4\ud2b8 \ud30c\uc77c data/names/[Language].txt \uc788\uc2b5\ub2c8\ub2e4. \uc774\uac83\uc744 array\ub85c \ubd84\ub9ac\ud558\uace0, Unicode\ub97c ASCII\ub85c \ubcc0\uacbd\ud558\uace0, \uc0ac\uc804 {language: [names ...]} \uc744 \ub9cc\ub4e4\uc5b4\uc11c \ub9c8\ubb34\ub9ac\ud569\ub2c8\ub2e4. from __future__ import unicode_literals, print_function, division from io import open import glob import os import unicodedata import string all_letters = string.ascii_letters + \" .,;\u0027-\" n_letters = len(all_letters) + 1 # EOS(end of sentence) \uae30\ud638 \ucd94\uac00 def findFiles(path): return glob.glob(path) # \uc720\ub2c8\ucf54\ub4dc \ubb38\uc790\uc5f4\uc744 ASCII\ub85c \ubcc0\ud658, https://stackoverflow.com/a/518232/2809427 def unicodeToAscii(s): return \u0027\u0027.join( c for c in unicodedata.normalize(\u0027NFD\u0027, s) if unicodedata.category(c) != \u0027Mn\u0027 and c in all_letters ) # \ud30c\uc77c\uc744 \uc77d\uace0 \uc904 \ub2e8\uc704\ub85c \ubd84\ub9ac def readLines(filename): with open(filename, encoding=\u0027utf-8\u0027) as some_file: return [unicodeToAscii(line.strip()) for line in some_file] # \uac01 \uc5b8\uc5b4\uc758 \uc774\ub984 \ubaa9\ub85d\uc778 category_lines \uc0ac\uc804 \uc0dd\uc131 category_lines = {} all_categories = [] for filename in findFiles(\u0027data/names/*.txt\u0027): category = os.path.splitext(os.path.basename(filename))[0] all_categories.append(category) lines = readLines(filename) category_lines[category] = lines n_categories = len(all_categories) if n_categories == 0: raise RuntimeError(\u0027Data not found. Make sure that you downloaded data \u0027 \u0027from https://download.pytorch.org/tutorial/data.zip and extract it to \u0027 \u0027the current directory.\u0027) print(\u0027# categories:\u0027, n_categories, all_categories) print(unicodeToAscii(\"O\u0027N\u00e9\u00e0l\")) # categories: 18 [\u0027English\u0027, \u0027Dutch\u0027, \u0027Spanish\u0027, \u0027Japanese\u0027, \u0027Portuguese\u0027, \u0027Arabic\u0027, \u0027Czech\u0027, \u0027Vietnamese\u0027, \u0027Irish\u0027, \u0027French\u0027, \u0027German\u0027, \u0027Russian\u0027, \u0027Italian\u0027, \u0027Chinese\u0027, \u0027Korean\u0027, \u0027Greek\u0027, \u0027Polish\u0027, \u0027Scottish\u0027] O\u0027Neal \ub124\ud2b8\uc6cc\ud06c \uc0dd\uc131# \uc774 \ub124\ud2b8\uc6cc\ud06c\ub294 \uc9c0\ub09c \ud29c\ud1a0\ub9ac\uc5bc\uc758 RNN \uc774 \ub2e4\ub978 \uc785\ub825\ub4e4\uacfc \uc5f0\uacb0\ub418\ub294 category tensor\ub97c \ucd94\uac00 \uc778\uc790\ub85c \uac00\uc9c0\uac8c \ud655\uc7a5\ud569\ub2c8\ub2e4. category tensor\ub294 \ubb38\uc790 \uc785\ub825\uacfc \ub9c8\ucc2c\uac00\uc9c0\ub85c one-hot \ubca1\ud130\uc785\ub2c8\ub2e4. \uc5ed\uc790\uc8fc: \uae30\uc874 \uc785\ub825\uacfc category tensor\ub97c \uacb0\ud569\ud558\uc5ec \uc785\ub825\uc73c\ub85c \uc0ac\uc6a9\ud558\uae30 \ub54c\ubb38\uc5d0 \uc785\ub825\uc758 \uc0ac\uc774\uc988\uac00 n_categories \ub9cc\ud07c \ucee4\uc9d1\ub2c8\ub2e4. \uc6b0\ub9ac\ub294 \ucd9c\ub825\uc744 \ub2e4\uc74c \ubb38\uc790\uc758 \ud655\ub960\ub85c \ud574\uc11d\ud569\ub2c8\ub2e4. \uc0d8\ud50c\ub9c1 \ud560 \ub54c, \uac00\uc7a5 \ud655\ub960\uc774 \ub192\uc740 \ubb38\uc790\uac00 \ub2e4\uc74c \uc785\ub825 \ubb38\uc790\ub85c \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \ub354 \ub098\uc740 \ub3d9\uc791\uc744 \uc704\ud574 \ub450 \ubc88\uc9f8 \uc120\ud615 \ub808\uc774\uc5b4 o2o (\uc740\ub2c9\uacfc \ucd9c\ub825\uc744 \uacb0\ud569\ud55c \ud6c4) \ub97c \ucd94\uac00\ud588\uc2b5\ub2c8\ub2e4 . \ub610\ud55c Drop-out \uacc4\uce35\uc774 \uc788\uc2b5\ub2c8\ub2e4. \uc774 \uacc4\uce35\uc740 \uc8fc\uc5b4\uc9c4 \ud655\ub960(\uc5ec\uae30\uc11c\ub294 0.1)\ub85c \ubb34\uc791\uc704\ub85c \uc785\ub825\uc744 0 # \uc73c\ub85c \ub9cc\ub4ed\ub2c8\ub2e4. \uc77c\ubc18\uc801\uc73c\ub85c \uc785\ub825\uc744 \ud750\ub9ac\uac8c \ud574\uc11c \uacfc\uc801\ud569\uc744 \ub9c9\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \uc5ec\uae30\uc11c \uc6b0\ub9ac\ub294 \uace0\uc758\ub85c \uc77c\ubd80 \ud63c\ub3c8\uc744 \ucd94\uac00\ud558\uace0 \uc0d8\ud50c\ub9c1 \ub2e4\uc591\uc131\uc744 \ub192\uc774\uae30 \uc704\ud574 \ub124\ud2b8\uc6cc\ud06c\uc758 \ub9c8\uc9c0\ub9c9\uc5d0 \uc774\uac83\uc744 \uc0ac\uc6a9\ud569\ub2c8\ub2e4. import torch import torch.nn as nn class RNN(nn.Module): def __init__(self, input_size, hidden_size, output_size): super(RNN, self).__init__() self.hidden_size = hidden_size self.i2h = nn.Linear(n_categories + input_size + hidden_size, hidden_size) self.i2o = nn.Linear(n_categories + input_size + hidden_size, output_size) self.o2o = nn.Linear(hidden_size + output_size, output_size) self.dropout = nn.Dropout(0.1) self.softmax = nn.LogSoftmax(dim=1) def forward(self, category, input, hidden): input_combined = torch.cat((category, input, hidden), 1) hidden = self.i2h(input_combined) output = self.i2o(input_combined) output_combined = torch.cat((hidden, output), 1) output = self.o2o(output_combined) output = self.dropout(output) output = self.softmax(output) return output, hidden def initHidden(self): return torch.zeros(1, self.hidden_size) \ud559\uc2b5# \ud559\uc2b5 \uc900\ube44# \uc81c\uc77c \uba3c\uc800 (category, line)\uc758 \ubb34\uc791\uc704 \uc30d\uc744 \uc5bb\ub294 \ud568\uc218: import random # \ubaa9\ub85d\uc5d0\uc11c \ubb34\uc791\uc704 \uc544\uc774\ud15c \ubc18\ud658 def randomChoice(l): return l[random.randint(0, len(l) - 1)] # \uc784\uc758\uc758 category \ubc0f \uadf8 category\uc5d0\uc11c \ubb34\uc791\uc704 \uc904(\uc774\ub984) \uc5bb\uae30 def randomTrainingPair(): category = randomChoice(all_categories) line = randomChoice(category_lines[category]) return category, line \uac01 \uc2dc\uac04 \ub2e8\uacc4 \ub9c8\ub2e4 (\uc989, \ud559\uc2b5 \ub2e8\uc5b4\uc758 \uac01 \ubb38\uc790 \ub9c8\ub2e4) \ub124\ud2b8\uc6cc\ud06c\uc758 \uc785\ub825\uc740 (\uc5b8\uc5b4, \ud604\uc7ac \ubb38\uc790, \uc740\ub2c9 \uc0c1\ud0dc) \uac00 \ub418\uace0, \ucd9c\ub825\uc740 (\ub2e4\uc74c \ubb38\uc790, \ub2e4\uc74c \uc740\ub2c9 \uc0c1\ud0dc) \uac00 \ub41c\ub2e4. \ub530\ub77c\uc11c \uac01 \ud559\uc2b5 \uc138\ud2b8 \ub9c8\ub2e4 \uc5b8\uc5b4, \uc785\ub825 \ubb38\uc790\uc758 \uc138\ud2b8, \ucd9c\ub825/\ubaa9\ud45c \ubb38\uc790\uc758 \uc138\ud2b8\uac00 \ud544\uc694\ud558\ub2e4. \uac01 \uc2dc\uac04 \ub2e8\uacc4\ub9c8\ub2e4 \ud604\uc7ac \ubb38\uc790\uc5d0\uc11c \ub2e4\uc74c \ubb38\uc790\ub97c \uc608\uce21\ud558\uae30 \ub54c\ubb38\uc5d0, \ubb38\uc790 \uc30d\uc740 \ud55c \uc904(\ud558\ub098\uc758 \uc774\ub984)\uc5d0\uc11c \uc5f0\uc18d\ub41c \ubb38\uc790 \uadf8\ub8f9\uc785\ub2c8\ub2e4. - \uc608\ub97c \ub4e4\uc5b4 \"ABCD\u003cEOS\u003e\" \ub294 (\u201cA\u201d, \u201cB\u201d), (\u201cB\u201d, \u201cC\u201d), (\u201cC\u201d, \u201cD\u201d), (\u201cD\u201d, \u201cEOS\u201d) \ub85c \uc0dd\uc131\ud569\ub2c8\ub2e4. Category(\uc5b8\uc5b4) Tensor\ub294 \u003c1 x n_categories\u003e \ud06c\uae30\uc758 One-hot Tensor \uc785\ub2c8\ub2e4. \ud559\uc2b5\uc2dc\uc5d0 \ubaa8\ub4e0 \uc2dc\uac04 \ub2e8\uacc4\uc5d0\uc11c \ub124\ud2b8\uc6cc\ud06c\uc5d0 \uc774\uac83\uc744 \uc804\ub2ec\ud569\ub2c8\ub2e4. - \uc774\uac83\uc740 \uc124\uacc4 \uc120\ud0dd\uc0ac\ud56d\uc73c\ub85c, \ucd08\uae30 \uc740\ub2c9 \uc0c1\ud0dc \ub610\ub294 \ub610 \ub2e4\ub978 \uc804\ub7b5\uc758 \ubd80\ubd84\uc73c\ub85c \ud3ec\ud568\ub420 \uc218 \uc788\uc2b5\ub2c8\ub2e4. # Category\ub97c \uc704\ud55c One-hot \ubca1\ud130 def categoryTensor(category): li = all_categories.index(category) tensor = torch.zeros(1, n_categories) tensor[0][li] = 1 return tensor # \uc785\ub825\uc744 \uc704\ud55c \ucc98\uc74c\ubd80\ud130 \ub9c8\uc9c0\ub9c9 \ubb38\uc790(EOS \uc81c\uc678)\uae4c\uc9c0\uc758 One-hot \ud589\ub82c def inputTensor(line): tensor = torch.zeros(len(line), 1, n_letters) for li in range(len(line)): letter = line[li] tensor[li][0][all_letters.find(letter)] = 1 return tensor # \ubaa9\ud45c\ub97c \uc704\ud55c \ub450\ubc88\uc9f8 \ubb38\uc790 \ubd80\ud130 \ub9c8\uc9c0\ub9c9(EOS)\uae4c\uc9c0\uc758 ``LongTensor`` def targetTensor(line): letter_indexes = [all_letters.find(line[li]) for li in range(1, len(line))] letter_indexes.append(n_letters - 1) # EOS return torch.LongTensor(letter_indexes) \ud559\uc2b5 \ub3d9\uc548 \ud3b8\uc758\ub97c \uc704\ud574 \ubb34\uc791\uc704\ub85c (category[\uc5b8\uc5b4], line[\uc774\ub984])\uc744 \uac00\uc838\uc624\uace0 \uadf8\uac83\uc744 \ud544\uc694\ud55c \ud615\ud0dc (category[\uc5b8\uc5b4], input[\ud604\uc7ac \ubb38\uc790], target[\ub2e4\uc74c \ubb38\uc790]) Tensor\ub85c \ubc14\uafb8\ub294 randomTrainingExample \ud568\uc218\ub97c \ub9cc\ub4e4 \uc608\uc815\uc785\ub2c8\ub2e4. # \uc784\uc758\uc758 Category\uc5d0\uc11c Category, Input, Target Tensor\ub97c \ub9cc\ub4ed\ub2c8\ub2e4. def randomTrainingExample(): category, line = randomTrainingPair() category_tensor = categoryTensor(category) input_line_tensor = inputTensor(line) target_line_tensor = targetTensor(line) return category_tensor, input_line_tensor, target_line_tensor \ub124\ud2b8\uc6cc\ud06c \ud559\uc2b5# \ub9c8\uc9c0\ub9c9 \ucd9c\ub825\ub9cc \uc0ac\uc6a9\ud558\ub294 \ubd84\ub958\uc640 \ub2ec\ub9ac, \ubaa8\ub4e0 \ub2e8\uacc4\uc5d0\uc11c \uc608\uce21\uc744 \uc218\ud589\ud558\ubbc0\ub85c \ubaa8\ub4e0 \ub2e8\uacc4\uc5d0\uc11c \uc190\uc2e4\uc744 \uacc4\uc0b0\ud569\ub2c8\ub2e4. Autograd\uc758 \ub9c8\ubc95\uc774 \uac01 \ub2e8\uacc4\uc758 \uc190\uc2e4\ub4e4\uc744 \uac04\ub2e8\ud558\uac8c \ud569\ud558\uace0 \ub9c8\uc9c0\ub9c9\uc5d0 \uc5ed\uc804\ud30c\ub97c \ud638\ucd9c\ud558\uac8c \ud574\uc90d\ub2c8\ub2e4. criterion = nn.NLLLoss() learning_rate = 0.0005 def train(category_tensor, input_line_tensor, target_line_tensor): target_line_tensor.unsqueeze_(-1) hidden = rnn.initHidden() rnn.zero_grad() loss = torch.Tensor([0]) # \ub610\ub294 \uadf8\ub0e5 ``loss = 0`` \uc744 \uc0ac\uc6a9\ud574\ub3c4 \ub429\ub2c8\ub2e4. for i in range(input_line_tensor.size(0)): output, hidden = rnn(category_tensor, input_line_tensor[i], hidden) l = criterion(output, target_line_tensor[i]) loss += l loss.backward() for p in rnn.parameters(): p.data.add_(p.grad.data, alpha=-learning_rate) return output, loss.item() / input_line_tensor.size(0) \ud559\uc2b5\uc5d0 \uac78\ub9ac\ub294 \uc2dc\uac04\uc744 \ucd94\uc801\ud558\uae30 \uc704\ud574 \uc0ac\ub78c\uc774 \uc77d\uc744 \uc218 \uc788\ub294 \ubb38\uc790\uc5f4\uc744 \ubc18\ud658\ud558\ub294``timeSince (timestamp)`` \ud568\uc218\ub97c \ucd94\uac00\ud569\ub2c8\ub2e4: import time import math def timeSince(since): now = time.time() s = now - since m = math.floor(s / 60) s -= m * 60 return \u0027%dm %ds\u0027 % (m, s) \ud559\uc2b5\uc740 \uc77c\uc0c1\uc801\uc778 \uc77c\uc785\ub2c8\ub2e4. - \uba87 \ubc88 train() \uc744 \ud638\ucd9c\ud558\uace0, \uba87 \ubd84 \uc815\ub3c4 \uae30\ub2e4\ub838\ub2e4\uac00 print_every \ub9c8\ub2e4 \ud604\uc7ac \uc2dc\uac04\uacfc \uc190\uc2e4\uc744 \ucd9c\ub825\ud558\uace0, \ub098\uc911\uc5d0 \ub3c4\uc2dd\ud654\ub97c \uc704\ud574 plot_every \ub9c8\ub2e4 all_losses \uc5d0 \ud3c9\uade0 \uc190\uc2e4\uc744 \uc800\uc7a5\ud569\ub2c8\ub2e4. rnn = RNN(n_letters, 128, n_letters) n_iters = 100000 print_every = 5000 plot_every = 500 all_losses = [] total_loss = 0 # ``plot_every`` \ub9c8\ub2e4 \ucd08\uae30\ud654 start = time.time() for iter in range(1, n_iters + 1): output, loss = train(*randomTrainingExample()) total_loss += loss if iter % print_every == 0: print(\u0027%s (%d %d%%) %.4f\u0027 % (timeSince(start), iter, iter / n_iters * 100, loss)) if iter % plot_every == 0: all_losses.append(total_loss / plot_every) total_loss = 0 0m 15s (5000 5%) 3.0273 0m 26s (10000 10%) 2.8095 0m 38s (15000 15%) 3.2219 0m 49s (20000 20%) 1.5323 1m 1s (25000 25%) 2.5673 1m 12s (30000 30%) 2.1202 1m 23s (35000 35%) 2.5683 1m 35s (40000 40%) 2.3383 1m 46s (45000 45%) 2.3752 1m 57s (50000 50%) 2.7899 2m 8s (55000 55%) 1.7466 2m 19s (60000 60%) 2.2184 2m 31s (65000 65%) 3.2277 2m 42s (70000 70%) 2.4214 2m 53s (75000 75%) 2.9422 3m 4s (80000 80%) 2.3035 3m 15s (85000 85%) 2.5719 3m 26s (90000 90%) 3.0298 3m 38s (95000 95%) 3.1836 3m 49s (100000 100%) 2.6175 \uc190\uc2e4 \ub3c4\uc2dd\ud654# all_losses\ub97c \uc774\uc6a9\ud55c \uc190\uc2e4\uc758 \ub3c4\uc2dd\ud654\ub294 \ub124\ud2b8\uc6cc\ud06c\uc758 \ud559\uc2b5 \uc0c1\ud0dc\ub97c \ubcf4\uc5ec\uc90d\ub2c8\ub2e4: import matplotlib.pyplot as plt plt.figure() plt.plot(all_losses) [\u003cmatplotlib.lines.Line2D object at 0x7f0dab102bd0\u003e] \ub124\ud2b8\uc6cc\ud06c \uc0d8\ud50c\ub9c1# \uc0d8\ud50c\ub9c1\uc744 \uc704\ud574\uc11c, \ub124\ud2b8\uc6cc\ud06c\uc5d0 \ud558\ub098\uc758 \uae00\uc790\ub97c \uc8fc\uace0 \ub2e4\uc74c \ubb38\uc790\ub97c \ubb3c\uc5b4\ubcf4\uace0 \uc774\uac83\uc744 \ub2e4\uc74c \ubb38\uc790\ub85c \uc804\ub2ec\ud558\ub294 \uac83\uc744 EOS \ud1a0\ud070\uae4c\uc9c0 \ubc18\ubcf5\ud569\ub2c8\ub2e4. \uc785\ub825 \uce74\ud14c\uace0\ub9ac(\uc5b8\uc5b4), \uc2dc\uc791 \ubb38\uc790, \ube44\uc5b4 \uc788\ub294 \uc740\ub2c9 \uc0c1\ud0dc\ub97c \uc704\ud55c Tensor\ub97c \uc0dd\uc131\ud558\uc2ed\uc2dc\uc624 \uc2dc\uc791 \ubb38\uc790\ub85c output_name \ubb38\uc790\uc5f4\uc744 \uc0dd\uc131\ud558\uc2ed\uc2dc\uc624 \ucd5c\ub300 \ucd9c\ub825 \uae38\uc774\uae4c\uc9c0, \ud604\uc7ac \ubb38\uc790\ub97c \ub124\ud2b8\uc6cc\ud06c\uc5d0 \uc804\ub2ec\ud558\uc2ed\uc2dc\uc624. \uac00\uc7a5 \ub192\uc740 \ucd9c\ub825\uc5d0\uc11c \ub2e4\uc74c \ubb38\uc790\uc640 \ub2e4\uc74c \uc740\ub2c9 \uc0c1\ud0dc\ub97c \uc5bb\uc73c\uc2ed\uc2dc\uc624 \ub9cc\uc77c \ubb38\uc790\uac00 EOS\uba74, \uc5ec\uae30\uc11c \uba48\ucd94\uc2ed\uc2dc\uc624 \ub9cc\uc77c \uc77c\ubc18\uc801\uc778 \ubb38\uc790\ub77c\uba74, output_name \uc5d0 \ucd94\uac00\ud558\uace0 \uacc4\uc18d\ud558\uc2ed\uc2dc\uc624 \ub9c8\uc9c0\ub9c9 \uc774\ub984\uc744 \ubc18\ud658\ud558\uc2ed\uc2dc\uc624 \ucc38\uace0 \uc2dc\uc791 \ubb38\uc790\ub97c \uc8fc\ub294 \uac83 \uc678\uc5d0 \u201c\ubb38\uc790\uc5f4 \uc2dc\uc791\u201d \ud1a0\ud070\uc744 \ud559\uc2b5\uc5d0 \ud3ec\ud568\ub418\uac8c \ud558\uace0 \ub124\ud2b8\uc6cc\ud06c\uac00 \uc790\uccb4\uc801\uc73c\ub85c \uc2dc\uc791 \ubb38\uc790\ub97c \uc120\ud0dd\ud558\uac8c \ud558\ub294 \ub2e4\ub978 \ubc29\ubc95\ub3c4 \uc788\uc2b5\ub2c8\ub2e4. max_length = 20 # \uce74\ud14c\uace0\ub9ac\uc640 \uc2dc\uc791 \ubb38\uc790\ub85c\ubd80\ud130 \uc0d8\ud50c\ub9c1 \ud558\uae30 def sample(category, start_letter=\u0027A\u0027): with torch.no_grad(): # \uc0d8\ud50c\ub9c1\uc5d0\uc11c \ud788\uc2a4\ud1a0\ub9ac\ub97c \ucd94\uc801\ud560 \ud544\uc694 \uc5c6\uc74c category_tensor = categoryTensor(category) input = inputTensor(start_letter) hidden = rnn.initHidden() output_name = start_letter for i in range(max_length): output, hidden = rnn(category_tensor, input[0], hidden) topv, topi = output.topk(1) topi = topi[0][0] if topi == n_letters - 1: break else: letter = all_letters[topi] output_name += letter input = inputTensor(letter) return output_name # \ud558\ub098\uc758 \uce74\ud14c\uace0\ub9ac\uc640 \uc5ec\ub7ec \uc2dc\uc791 \ubb38\uc790\ub4e4\ub85c \uc5ec\ub7ec \uac1c\uc758 \uc0d8\ud50c \uc5bb\uae30 def samples(category, start_letters=\u0027ABC\u0027): for start_letter in start_letters: print(sample(category, start_letter)) samples(\u0027Russian\u0027, \u0027RUS\u0027) samples(\u0027German\u0027, \u0027GER\u0027) samples(\u0027Spanish\u0027, \u0027SPA\u0027) samples(\u0027Chinese\u0027, \u0027CHI\u0027) Rakovak Uantovov Shillov Gerren Eren Rour Salla Pares Allan Chin Han Iun Exercises# Try with a different dataset of category -\u003e line, for example: Fictional series -\u003e Character name Part of speech -\u003e Word Country -\u003e City Use a \u201cstart of sentence\u201d token so that sampling can be done without choosing a start letter Get better results with a bigger and/or better shaped network Try the nn.LSTM and nn.GRU layers \uc0c1\uc704 \uc218\uc900 \ub124\ud2b8\uc6cc\ud06c\ub85c \uc5ec\ub7ec \uac1c\uc758 \uc774\ub7f0 RNN\uc744 \uacb0\ud569\ud574 \ubcf4\uc2ed\uc2dc\uc624 Total running time of the script: (3 minutes 49.522 seconds) Download Jupyter notebook: char_rnn_generation_tutorial.ipynb Download Python source code: char_rnn_generation_tutorial.py Download zipped: char_rnn_generation_tutorial.zip",
       "author": {
         "@type": "Organization",
         "name": "PyTorch Contributors",
         "url": "https://pytorch.org"
       },
       "image": "../_static/img/pytorch_seo.png",
       "mainEntityOfPage": {
         "@type": "WebPage",
         "@id": "/intermediate/char_rnn_generation_tutorial.html"
       },
       "datePublished": "2023-01-01T00:00:00Z",
       "dateModified": "2023-01-01T00:00:00Z"
     }
 

article:modified_time2022-11-30T07:09:41+00:00
og:typearticle
og:site_namePyTorch Tutorials KR
og:image../_static/img/pytorch_seo.png
og:image:altPyTorch Tutorials KR
og:ignore_canonicaltrue
docsearch:languageko
docbuild:last-update2022년 11월 30일
None1
pytorch_projecttutorials

Links:

https://pytorch.kr/
PyTorch 시작하기 https://pytorch.kr/get-started/locally/
기본 익히기 https://tutorials.pytorch.kr/beginner/basics/intro.html
한국어 튜토리얼 https://tutorials.pytorch.kr/
한국어 모델 허브 https://pytorch.kr/hub/
Official Tutorials https://docs.pytorch.org/tutorials/
블로그 https://pytorch.kr/blog/
PyTorch API https://docs.pytorch.org/docs/
Domain API 소개 https://pytorch.kr/domains/
한국어 튜토리얼 https://tutorials.pytorch.kr/
Official Tutorials https://docs.pytorch.org/tutorials/
한국어 커뮤니티 https://discuss.pytorch.kr/
개발자 정보 https://pytorch.kr/resources/
Landscape https://landscape.pytorch.org/
https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html
https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html
PyTorch 시작하기https://pytorch.kr/get-started/locally/
기본 익히기https://tutorials.pytorch.kr/beginner/basics/intro.html
한국어 튜토리얼https://tutorials.pytorch.kr/
한국어 모델 허브https://pytorch.kr/hub/
Official Tutorialshttps://docs.pytorch.org/tutorials/
블로그https://pytorch.kr/blog/
PyTorch APIhttps://docs.pytorch.org/docs/
Domain API 소개https://pytorch.kr/domains/
한국어 튜토리얼https://tutorials.pytorch.kr/
Official Tutorialshttps://docs.pytorch.org/tutorials/
한국어 커뮤니티https://discuss.pytorch.kr/
개발자 정보https://pytorch.kr/resources/
Landscapehttps://landscape.pytorch.org/
Skip to main contenthttps://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#main-content
v2.8.0+cu128https://tutorials.pytorch.kr/index.html
Intro https://tutorials.pytorch.kr/intro.html
Compilers https://tutorials.pytorch.kr/compilers_index.html
Domains https://tutorials.pytorch.kr/domains.html
Distributed https://tutorials.pytorch.kr/distributed.html
Deep Dive https://tutorials.pytorch.kr/deep-dive.html
Extension https://tutorials.pytorch.kr/extension.html
Ecosystem https://tutorials.pytorch.kr/ecosystem.html
Recipes https://tutorials.pytorch.kr/recipes_index.html
한국어 튜토리얼 GitHub 저장소https://github.com/PyTorchKorea/tutorials-kr
파이토치 한국어 커뮤니티https://discuss.pytorch.kr/
Intro https://tutorials.pytorch.kr/intro.html
Compilers https://tutorials.pytorch.kr/compilers_index.html
Domains https://tutorials.pytorch.kr/domains.html
Distributed https://tutorials.pytorch.kr/distributed.html
Deep Dive https://tutorials.pytorch.kr/deep-dive.html
Extension https://tutorials.pytorch.kr/extension.html
Ecosystem https://tutorials.pytorch.kr/ecosystem.html
Recipes https://tutorials.pytorch.kr/recipes_index.html
한국어 튜토리얼 GitHub 저장소https://github.com/PyTorchKorea/tutorials-kr
파이토치 한국어 커뮤니티https://discuss.pytorch.kr/
https://tutorials.pytorch.kr/index.html
Go to the endhttps://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#sphx-glr-download-intermediate-char-rnn-generation-tutorial-py
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#nlp-rnn
Sean Robertsonhttps://github.com/spro
황성수https://github.com/adonisues
기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기https://tutorials.pytorch.kr/intermediate/char_rnn_classification_tutorial.html
기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 생성하기https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html
기초부터 시작하는 NLP: Sequence to Sequence 네트워크와 Attention을 이용한 번역https://tutorials.pytorch.kr/intermediate/seq2seq_translation_tutorial.html
기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기https://tutorials.pytorch.kr/intermediate/char_rnn_classification_tutorial.html
https://pytorch.org/https://pytorch.org/
PyTorch로 딥러닝하기: 60분만에 끝장내기https://tutorials.pytorch.kr/beginner/deep_learning_60min_blitz.html
예제로 배우는 파이토치(PyTorch)https://tutorials.pytorch.kr/beginner/pytorch_with_examples.html
Torch 사용자를 위한 PyTorchhttps://tutorials.pytorch.kr/beginner/former_torchies_tutorial.html
The Unreasonable Effectiveness of Recurrent Neural Networkshttps://karpathy.github.io/2015/05/21/rnn-effectiveness/
Understanding LSTM Networkshttps://colah.github.io/posts/2015-08-Understanding-LSTMs/
기초부터 시작하는 NLP: 문자-단위 RNN으로 이름 분류하기https://tutorials.pytorch.kr/intermediate/char_rnn_classification_tutorial.html
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id2
여기https://download.pytorch.org/tutorial/data.zip
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id4
지난 튜토리얼의 RNNhttps://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#Creating-the-Network
무작위로 입력을 0 #https://arxiv.org/abs/1207.0580
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id5
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id6
One-hot Tensorhttps://en.wikipedia.org/wiki/One-hot
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id7
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id8
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id9
#https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#exercises
Download Jupyter notebook: char_rnn_generation_tutorial.ipynbhttps://tutorials.pytorch.kr/_downloads/a75cfadf4fa84dd594874d4c53b62820/char_rnn_generation_tutorial.ipynb
Download Python source code: char_rnn_generation_tutorial.pyhttps://tutorials.pytorch.kr/_downloads/322506af160d5e2056afd75de1fd34ee/char_rnn_generation_tutorial.py
Download zipped: char_rnn_generation_tutorial.ziphttps://tutorials.pytorch.kr/_downloads/3af0543b3600b020bfdbf10ab130c2f8/char_rnn_generation_tutorial.zip
PyData Sphinx Themehttps://pydata-sphinx-theme.readthedocs.io/en/stable/index.html
데이터 준비https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id2
네트워크 생성https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id4
학습https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id5
학습 준비https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id6
네트워크 학습https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id7
손실 도식화https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id8
네트워크 샘플링https://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#id9
Exerciseshttps://tutorials.pytorch.kr/intermediate/char_rnn_generation_tutorial.html#exercises
torchaohttps://docs.pytorch.org/ao
torchrechttps://docs.pytorch.org/torchrec
torchfthttps://docs.pytorch.org/torchft
TorchCodechttps://docs.pytorch.org/torchcodec
torchvisionhttps://docs.pytorch.org/vision
ExecuTorchhttps://docs.pytorch.org/executorch
PyTorch on XLA Deviceshttps://docs.pytorch.org/xla
GitHub로 이동https://github.com/PyTorchKorea
튜토리얼로 이동https://tutorials.pytorch.kr/
커뮤니티로 이동https://discuss.pytorch.kr/
https://pytorch.kr/
파이토치 한국 사용자 모임https://pytorch.kr/
사용자 모임 소개https://pytorch.kr/about
기여해주신 분들https://pytorch.kr/contributors
리소스https://pytorch.kr/resources/
행동 강령https://pytorch.kr/coc
행동 강령https://pytorch.kr/coc
Linux Foundation의 정책https://www.linuxfoundation.org/policies/
our code of conducthttps://pytorch.kr/coc
Linux Foundation's policieshttps://www.linuxfoundation.org/policies/
Cookies Policyhttps://www.facebook.com/policies/cookies/
Sphinxhttps://www.sphinx-doc.org/
PyData Sphinx Themehttps://pydata-sphinx-theme.readthedocs.io/en/stable/index.html

Viewport: width=device-width, initial-scale=1


URLs of crawlers that visited me.