전체 글

코딩으로 4차 산업혁명에 대비하자
논문 리뷰

Attention is all you need (NeurIPS, 2017) code review

https://www.youtube.com/watch?v=AA621UofTUA&t=2706s 동빈나 님의 [딥러닝 기계 번역] Transformer: Attention Is All You Need (꼼꼼한 딥러닝 논문 리뷰와 코드 실습) 을 보고 코드를 리뷰해봤다. 설명을 너무 잘해주신다 갓갓,,, 복받으십쇼 동빈나님의 깃허브를 많이 참고했지만 중간중간 라이브러리 문제때문에 코드 수정을 추가로 진행했다. pytorch에서 제공하는 텍스트 분류 라이브러리 torchtext를 install 해준다 !pip install torchtext==0.6.0 preprocessing spacy 라이브러리를 이용해서 영어와 독일어의 전처리 모듈을 설치한다 %%capture !python -m spacy download..

논문 리뷰

Attention is all you need (NeurIPS, 2017) paper review

BERT,GPT 등 언어 모델에서 큰 영향을 준 transformer 모델이 해당 논문에서 발표되었다. 밑바닥 부터 시작하는 딥러닝 2 책에서도 attention 파트에서 설명하고 있는 모델이다. 논문 이해 후 코드 리뷰로 넘어갈것이다. 해당 포스팅에서는 논문 설명만을 먼저 한다. 완전히 번역하기 보다는 내가 이해하고 싶어서 paraphrasing을 좀 했다는것 주의할것 논문은 여기서 https://arxiv.org/pdf/1706.03762.pdf Abstract 통상적인 시퀀스 변환 모델은 반복 또는 encoder와 decoder를 포함하는 CNN (합성곱 신경망)을 기반으로 한다. 이 논문에서는 attention 메커니즘을 기반으로 하는 간단한 아키텍처인 transformer를 제안한다. 이 모델은..

Python

pytorch 이미지 모델링 II

모델 정의 nn.Module 상속 클래스 정의 nn.Module을 상속받는 클래스 정의 __init__(): 모델에서 사용될 모듈과 활성화 함수 등을 정의 forward(): 모델에서 실행되어야 하는 연산을 정의 class Model(nn.Module): def __init__(self,inputs):#초기화 super(Model,self).__init__() self.layer = nn.Linear(inputs,1) self.activation = nn.Sigmoid() def forward(self,x): x = self.layer(x) x = self.activation(x) return x model = Model(1) print(list(model.children())) print(list(mo..

Python

pytorch 이미지 모델링

토치비전(torchvision)은 파이토치에서 제공하는 데이터셋들이 모여있는 패키지 transforms: 전처리할 때 사용하는 메소드 (https://pytorch.org/docs/stable/torchvision/transforms.html) transforms에서 제공하는 클래스 이외는 일반적으로 클래스를 따로 만들어 전처리 단계를 진행 import torch from torch.utils.data import Dataset,DataLoader import torchvision.transforms as transforms from torchvision import datasets DataLoader의 인자로 들어갈 transform을 미리 정의할 수 있고, Compose를 통해 리스트 안에 순서대로 ..

Python

pytorch 기본문법 II

강의 출처: https://www.youtube.com/watch?v=k60oT_8lyFw&list=LL&index=1&t=4103s 텐서의 조작(manipulations) 인덱싱(Indexing): NumPy처럼 인덱싱 형태로 사용가능 x = torch.Tensor([[1,2],#0위치 [3,4]])#1위치 print(x) print(x[0,0]) print(x[0,1]) print(x[1,0]) print(x[1,1]) print(x[:, 0]) print(x[:, 1]) print(x[0:, ]) print(x[1:, ]) tensor([[1., 2.], [3., 4.]]) tensor(1.) tensor(2.) tensor(3.) tensor(4.) tensor([1., 3.]) tensor([2..

Python

pytorch 기본 문법 I

강의 출처: https://www.youtube.com/watch?v=k60oT_8lyFw&list=LL&index=1&t=4103s 파이토치 구성요소 torch.autograd: 자동 미분 기능 torch.nn: 신경망 구축을 위한 데이터 구조나 레이어 등의 라이브러리 torch.multiprocessing: 병렬처리 기능 torch.optim: SGD(Stochastic Gradient Descent)를 중심으로 한 파라미터 최적화 알고리즘 torch.utils: 데이터 조작 등 유틸리티 기능 torch.onnx: ONNX(Open Neural Network Exchange), 서로 다른 프레임워크 간의 모델을 공유 Tensor 텐서 0D tensor : 스칼라, rank 0, shape: ( ) -..

Deep Learning/from scratch II

[밑바닥부터 시작하는 딥러닝 2] - 8장 어텐션 III

어텐션에 관한 남은 이야기 양방향 RNN 양방향 LSTM은 역방향으로 처리하는 LSTM 계층도 추가한다. 각 시각에서는 이 두 LSTM 계층의 은닉 상태를 연결 시킨 벡터를 최종 은닉 상태로 처리한다(연결 외 합(sum), 평균(average) 내는 방법도 있다) 양방향으로 처리함으로써 각 단어에 대응하는 은닉상태 벡터에는 좌와 우 양쪽 방향으로부터의 정보를 집약하여 균형 잡힌 정보가 인코딩 되게 한다. 입력문장을 왼쪽->오른쪽(순방향 LSTM) 과 오른쪽->왼쪽(역방향 LSTM) 각 출력을 연결되게 한다. 출처: https://github.com/oreilly-japan/deep-learning-from-scratch-2/blob/master/common/time_layers.py class TimeB..

Deep Learning/from scratch II

[밑바닥부터 시작하는 딥러닝 2] - 8장 어텐션 II

어텐션을 갖춘 seq2seq 구현 Encoder 구현 앞의 Encoder 클래스는 LSTM의 계층의 마지막 은닉 상태 벡터를 반환한 반면, 모든 은닉 상태를 반환하여 구현한다. # coding: utf-8 import sys sys.path.append('..') from time_layers import * from seq2seq import Encoder, Seq2seq from attention_layer import TimeAttention class AttentionEncoder(Encoder): def forward(self, xs): xs = self.embed.forward(xs) hs = self.lstm.forward(xs) return hs #모든 은닉상태 벡터 def backward..

해파리냉채무침
#일간코딩챌린지