๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Deep Learning

(6)
LSTM(Long Short-Term Memories model) ๊ตฌํ˜„ ํŒŒ์ดํ† ์น˜๋ฅผ ์ด์šฉํ•˜์—ฌ LSTM(Long Short-Term Memories model)์„ ๊ตฌํ˜„ํ•  ๊ฒƒ์ด๋‹ค. ์‚ฌ์šฉ๋  ๋ฐ์ดํ„ฐ๋Š” ์•„๋งˆ์กด์˜ ์ฃผ๊ฐ€๋กœ ์ข…๊ฐ€์™€ ๊ฑฐ๋ž˜๋Ÿ‰์„ ์ด์šฉํ•˜์—ฌ, ์ผ์ฃผ์ผ ๋’ค์˜ ์ข…๊ฐ€๋ฅผ ์˜ˆ์ธกํ•˜๋Š” ๊ฒƒ์ด ๋ชฉ์ ์ด๋‹ค. ๋ฐ์ดํ„ฐ๋Š” ์—ฌ๊ธฐ(www.kaggle.com/camnugent/sandp500)์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ์ดํ„ฐ๊ตฌํ˜„ ๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ 2. ๋ชจ๋ธ ์„ค์ • 3. ๋ชจ๋ธ ํ•™์Šต 4. ํ•™์Šต ๊ฒฐ๊ณผ 1. ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ In: import pandas as pd from numpy import array from numpy import hstack import matplotlib.pyplot as plt import torch def min_max_scaler(arr): min_arr = min(arr)..
์ˆœํ™˜ ์‹ ๊ฒฝ๋ง(Recurrent Neural Network) ๊ตฌํ˜„ ํŒŒ์ดํ† ์น˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ˆœํ™˜ ์‹ ๊ฒฝ๋ง(Recurrent Neural Network)๋ฅผ ๊ตฌํ˜„ํ•  ๊ฒƒ์ด๋‹ค. ๊ตฌํ˜„ ๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ 2. ๋ชจ๋ธ ์„ค์ • 3. ๋ชจ๋ธ ํ•™์Šต 4. ํ•™์Šต ๊ฒฐ๊ณผ 1. ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ In: import torch import torch.nn as nn import torch.optim as optim import numpy as np string = "To climb steep hills requires a slow pace at first." chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ?!.,:;'01" char_list = [i for i in chars] n_letter = len(chars) def s..
ํ•ฉ์„ฑ๊ณฑ ์‹ ๊ฒฝ๋ง(Convolutional Neural Network) ๊ตฌํ˜„ MNIST ๋ฐ์ดํ„ฐ์˜ ์†๊ธ€์”จ๋กœ ์ ํžŒ ์ˆซ์ž ์ด๋ฏธ์ง€๋ฅผ ๋ถ„๋ฅ˜ํ•˜๋Š” ๋‹ค์ค‘ ๋ถ„๋ฅ˜(Multiclass classification) ๋ฌธ์ œ๋ฅผ ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค. ์•ž์˜ ํฌ์ŠคํŒ… "[Model] 01. ์ธ๊ณต์‹ ๊ฒฝ๋ง(Artificial Neural Network) ๊ตฌํ˜„"๊ณผ ์ค‘๋ณต๋˜๋Š” ๋‚ด์šฉ์— ๋Œ€ํ•ด ๋‹ค๋ฃจ์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค. ํ•„์š”ํ•˜๋ฉด ๋‹ค์Œ ๋งํฌ๋ฅผ ํ†ตํ•ด ์ฐธ๊ณ ํ•˜๋„๋ก ํ•˜์ž. [Model] 01. ์ธ๊ณต์‹ ๊ฒฝ๋ง(Artificial Neural Network) ๊ตฌํ˜„ MNIST ๋ฐ์ดํ„ฐ์˜ ์†๊ธ€์”จ๋กœ ์ ํžŒ ์ˆซ์ž ์ด๋ฏธ์ง€๋ฅผ ๋ถ„๋ฅ˜ํ•˜๋Š” ๋‹ค์ค‘ ๋ถ„๋ฅ˜(Multiclass classification) ๋ฌธ์ œ๋ฅผ ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค. ๋ฐ์ดํ„ฐ๋Š” ์—ฌ๊ธฐ(https://www.kaggle.com/c/digit-recognizer)์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. ํŒŒ์ดํ† ์น˜๋ฅผ ์ด.. rooney-song.tisto..
์ธ๊ณต์‹ ๊ฒฝ๋ง(Artificial Neural Network) ๊ตฌํ˜„ MNIST ๋ฐ์ดํ„ฐ์˜ ์†๊ธ€์”จ๋กœ ์ ํžŒ ์ˆซ์ž ์ด๋ฏธ์ง€๋ฅผ ๋ถ„๋ฅ˜ํ•˜๋Š” ๋‹ค์ค‘ ๋ถ„๋ฅ˜(Multiclass classification) ๋ฌธ์ œ๋ฅผ ๋‹ค๋ฃฐ ๊ฒƒ์ด๋‹ค. ๋ฐ์ดํ„ฐ๋Š” ์—ฌ๊ธฐ(https://www.kaggle.com/c/digit-recognizer)์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. ํŒŒ์ดํ† ์น˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ธ๊ณต์‹ ๊ฒฝ๋ง(Artificial Neural Network)์„ ๊ตฌํ˜„ํ•  ๊ฒƒ์ด๋‹ค. ๊ตฌํ˜„ ๊ณผ์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ๋ฐ์ดํ„ฐ ์ž…๋ ฅ ๋ฐ ํ™•์ธ 2. ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ 3. ๋ชจ๋ธ ์„ค์ • 4. ๋ฐ์ดํ„ฐ ํ•™์Šต ๋ฐ ๊ฒ€์ฆ 1. ๋ฐ์ดํ„ฐ ์ž…๋ ฅ ๋ฐ ํ™•์ธ In: import numpy as np import pandas as pd from sklearn.model_selection import train_test_split import torch import torch.nn ..
์ž๋™ ๋ฏธ๋ถ„(Automatic differentiation) ์‚ฌ์šฉ๋ฒ• ํŒŒ์ดํ† ์น˜์˜ ์ž๋™ ๋ฏธ๋ถ„(Auto differentiation)์„ ์ด์šฉํ•œ ๋ณ€ํ™”๋„(Gradient) ๊ณ„์‚ฐ ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณผ ๊ฒƒ์ด๋‹ค. ๋‹ค๋ฃฐ ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ์ž๋™ ๋ฏธ๋ถ„ ์ค€๋น„ 2. ๋ณ€ํ™”๋„ ๊ณ„์‚ฐ 1. ์ž๋™ ๋ฏธ๋ถ„ ์ค€๋น„ In: import torch x = torch.ones(2, 2, requires_grad = True) print(x) Out: tensor([[1., 1.], [1., 1.]], requires_grad=True) โ–ท torch.ones()์— ํ…์„œ ํฌ๊ธฐ์— ๋Œ€ํ•œ ์ธ์ž์™€ requires_grad ์ธ์ž๋ฅผ ์ฃผ์–ด ํ…์„œ๋ฅผ ์ƒ์„ฑํ•˜์˜€๋‹ค. ๊ฒฐ๊ณผ ์ฐฝ์— requires_grad=True๊ฐ€ ๋‚˜ํƒ€๋‚œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋Š” ์ดํ›„ ์—ญ์ „ํŒŒ ๊ณผ์ •์„ ์ˆ˜ํ–‰ ํ›„, ํ•ด๋‹น ํ…์„œ์˜ ๋ณ€ํ™”๋„๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค. In: y = ..
ํ…์„œ(Tensor) ์‚ฌ์šฉ๋ฒ• ํŒŒ์ดํ† ์น˜์˜ ํ…์„œ(Tensor)์˜ ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž. ๋‹ค๋ฃฐ ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. 1. ํ…์„œ์˜ ์ƒ์„ฑ 2. ํ…์„œ์˜ ์—ฐ์‚ฐ 3. ํ…์„œ์˜ ๋ณ€ํ™˜ 1. ํ…์„œ์˜ ์ƒ์„ฑ In: import torch x = torch.rand(5, 3) print(x) Out: tensor([[0.1501, 0.8814, 0.4848], [0.0723, 0.9468, 0.1327], [0.8581, 0.8050, 0.4441], [0.4888, 0.0157, 0.6959], [0.9666, 0.4729, 0.1983]]) โ–ท torch.rand()๋ฅผ ์ด์šฉํ•˜์—ฌ 0๊ณผ 1 ์‚ฌ์ด์˜ ์ž„์˜์˜ ์ˆ˜๊ฐ€ ์›์†Œ์ธ 5×3 ํ–‰๋ ฌ์ด ๋งŒ๋“ค์—ˆ๋‹ค. ํ•จ์ˆ˜ ์•ˆ์˜ ๋‘ ์ธ์ž๋Š” ํ–‰๊ณผ ์—ด์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. In: x = torch.rand(5, 3, 3) print(x) Out:..