[Day14] RNN
RNN 맛보기
RNN - Sequential Models
Transformer - Sequential Models
중요
LSTM의 내용 정리
nn.LSTM
nn.LSTM(input_size=28,hidden_size=256,num_layers=3,batch_first=True)
기본적으로 쓰이는 인자들만 예시로 넣었다. 아래는 LSTM의 인자들의 설명이다. 여기서 batch_first
는 LSTM의 output이 어떤식으로 나올지 이다.
input_size
: The number of expected features in the input x
hidden_size
: The number of features in the hidden state h
num_layers
: Number of recurrent layers. E.g., setting num_layers=2
would mean stacking two LSTMs together to form a stacked LSTM
,
with the second LSTM taking in outputs of the first LSTM and
computing the final results. Default: 1
bias
: If False
, then the layer does not use bias weights b_ih
and b_hh
.
Default: True
batch_first
: If True
, then the input and output tensors are provided
as (batch, seq, feature). Default: False
dropout
: If non-zero, introduces a Dropout
layer on the outputs of each
LSTM layer except the last layer, with dropout probability equal to
dropout
. Default: 0
bidirectional
: If True
, becomes a bidirectional LSTM. Default: False
LSTM의 결과와 각 벡터의 shape은 다음과 같다.
N: number of batches
L: sequence lengh
Q: input dim
K: number of layers
D: LSTM feature dimension
Y,(hn,cn) = LSTM(X)
X: [N x L x Q] - N input sequnce of length L with Q dim.
Y: [N x L x D] - N output sequnce of length L with D feature dim.
hn: [K x N x D] - K (per each layer) of N final hidden state with D feature dim.
cn: [K x N x D] - K (per each layer) of N final hidden state with D cell dim.
피어세션
- 백준 11725번: 트리의 부모 찾기 문제를 풀고 토론 하였다.
#방법 1
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
def find_parent(n):
for i in node[n]:
if result[i] == 0:
result[i]=n
find_parent(i)
N=int(input())
node=defaultdict(list)
result=[0]*(N+1)
result[1]=1
for _ in range(N-1):
a,b=map(int,sys.stdin.readline().split())
node[a].append(b)
node[b].append(a)
find_parent(1)
print(*result[2:],sep='\n',end='')
#방법 2
import sys
from collections import defaultdict
from collections import deque
N=int(input())
node=defaultdict(list)
result=[0]*(N+1)
for _ in range(N-1):
a,b=map(int,sys.stdin.readline().split())
node[a].append(b)
node[b].append(a)
q=deque()
q.appendleft(1)
result[1]=1
while q:
parent=q.pop()
for n in node[parent]:
if result[n]==0:
result[n]=parent
q.appendleft(n)
print(*result[2:],sep='\n',end='')
- git에 대해서 정리하고 같이 공부를 진행함.
'AI > 부스트 캠프 AI tech' 카테고리의 다른 글
[Day18] Seq2Seq (0) | 2021.02.17 |
---|---|
[Day17] LSTM and GRU (0) | 2021.02.16 |
[Day16] NLP 기초 (0) | 2021.02.15 |
[Day15] Generative model (0) | 2021.02.05 |
[Day13] CNN (0) | 2021.02.03 |
[Day12] 최적화 (0) | 2021.02.02 |
[Day11] 딥러닝 기초 (0) | 2021.02.01 |
[Day10] 시각화/통계학 (0) | 2021.01.29 |