[Day14] RNN

2021. 2. 4. 22:54·AI/부스트 캠프 AI tech

[Day14] RNN

  • RNN 맛보기

    • https://n-brogrammer.tistory.com/76
  • RNN - Sequential Models

    • https://n-brogrammer.tistory.com/77
  • Transformer - Sequential Models

    • https://n-brogrammer.tistory.com/78

 

 

중요

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
'AI/부스트 캠프 AI tech' 카테고리의 다른 글
  • [Day16] NLP 기초
  • [Day15] Generative model
  • [Day13] CNN
  • [Day12] 최적화
N-analyst
N-analyst
  • N-analyst
    개발자CuCu
    N-analyst
  • 전체
    오늘
    어제
  • 공지사항

    • 티스토리에서 원하는 글 찾는 방법
    • 분류 전체보기 (140)
      • 티스토리 (4)
      • 알고리즘 (5)
        • 알고리즘 정리 (1)
        • 백준 (4)
      • 마크다운(Typora) (13)
        • 사용법 (13)
      • 에러 (1)
        • 파이썬 (1)
      • 데이터 분석 (5)
        • python_analysis (3)
        • Machine Learning (2)
      • AI (109)
        • 파이토치로 시작하는 딥러닝 기초 (2)
        • 부스트 캠프 AI tech (41)
        • 이론 (66)
      • 파이썬(python) (1)
        • 기타 (1)
      • 웹 프로그래밍 (1)
        • 설정 팁 (1)
  • 블로그 메뉴

    • 홈
    • 태그
  • 인기 글

  • 최근 글

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.6
N-analyst
[Day14] RNN
상단으로

티스토리툴바