TIL
  • Main
  • TIL : ML
    • AI News
      • AI-powered coding, free of charge with Colab
    • Paper
      • Retrieval-augmented generation for knowledge-intensive nlp tasks
        • reference 정리
      • Sequence to Sequence
    • Generative AI
      • LLM
        • 기본 개념
    • Boostcamp
      • Daily Report
        • 2021
          • 09
            • week4
            • week5
          • 10
            • week1
            • week2
            • week3
            • week4
          • 11
            • week1
            • week2
            • week3
            • week4
            • week5
          • 12
            • week1
            • week2
            • week3
      • Final Project
        • 프로젝트 기획
          • 🌟최종 프로젝트 기획
          • 최종 프로젝트 Version
          • 아이디어 수집
          • 욕설, 혐오발언 감지
          • 라이브 커머스 레포팅 프로젝트
        • 프로젝트 진행
          • week1
          • week2
          • week3
      • Competition
        • 1. [NLP] 문장 내 개체간 관계 추출
          • Day1 (9.27, 월)
          • Day2-3 (9.28~29, 화~수)
          • Day4 (9.30, 목)
          • Day5 (10.1, 금)
          • Day6~7 (10.2~3, 토~일)
          • Day8 (10.4, 월)
          • Day9 (10.5, 화)
          • Day10 (10.6, 수)
          • Day 11 (10.7 목)
        • 2. [NLP] MRC 프로젝트
          • Day1 (10.25, 월)
          • Day2 (10.26, 화)
          • Day3 (10.27, 수)
          • Day4-5 (10.28-29, 목-금)
          • Day6 (11.1, 월)
          • Day7 (11.2, 화)
          • Day8 (11.3, 수)
          • Day9 (11.4, 목)
        • 🔨3. [NLP] 데이터 제작
          • Day1
        • 🔨4. [공통] 모델 경량화
      • [U Stage] - DL basic
        • (01강) 딥러닝 기본 용어 설명 - Historical Review
        • (02강) 뉴럴 네트워크 - MLP (Multi-Layer Perceptron)
        • (03강) Optimization
        • 🔨(04강) Convolution은 무엇인가?
        • 🔨(05강) Modern CNN - 1x1 convolution의 중요성
        • 🔨(06강) Computer Vision Applications
        • (07강) Sequential Models - RNN
        • (08강) Sequential Models - Transformer
        • Page 2
      • [U Stage] - PyTorch
        • (01강) Introduction to PyTorch
        • (02강) PyTorch Basics
        • (03강) PyTorch 프로젝트 구조 이해하기
        • (04강) AutoGrad & Optimizer
        • (05강) Dataset & Dataloader
        • (06강) 모델 불러오기
        • (07강) Monitoring tools for PyTorch
        • (08강) Multi-GPU 학습
        • (09강) Hyperparameter Tuning
        • (10강) PyTorch Troubleshooting
      • [U Stage] - NLP
        • (01강) Introduction to NLP, Bag-of-Words
        • (02강) Word Embedding
        • (03강) Recurrent Neural Network and Language Modeling
        • (04강) LSTM and GRU
        • (05강) Sequence to Sequence with Attention
        • (06강) Beam Search and BLEU score
        • (07-08강) Transformer
        • (09강) Self-supervised Pre-training Models
      • [P Stage] - KLUE
        • (1강) 인공지능과 자연어 처리
        • (2강) 자연어의 전처리
        • (3강) BERT 언어모델 소개
        • (4강) 한국어 BERT 언어 모델 학습
        • (5강) BERT 기반 단일 문장 분류 모델 학습
        • (6강) BERT 기반 두 문장 관계 분류 모델 학습
        • (7강) BERT 언어모델 기반의 문장 토큰 분류
        • 오피스아워 (9.30, 목)
        • (8강) GPT 언어 모델
        • (9강) GPT 언어모델 기반의 자연어 생성
        • (10강) 최신 자연어처리 연구
      • [P Stage] - MRC
        • Before Study
        • (1강) MRC Intro & Python Basics
        • (2강) Extraction-based MRC
        • (3강) Generation-based MRC
        • (4강) Passage Retrieval - Sparse Embedding
        • (5강) Passage Retrieval - Dense Embedding
        • 오피스아워
        • (6강) Scaling up with FAISS
        • (7강) Linking MRC and Retrieval
        • (8강) Reducing Training Bias
        • (9강) Closed-book QA with T5
        • (10강) QA with Phrase Retrieval
        • 마스터클래스
      • [P Stage] - 데이터제작(NLP)
        • (1강) 데이터 제작의 A to Z
        • (2강) 자연어처리 데이터 기초
        • (3강) 자연어처리 데이터 소개 1
        • (4강) 자연어처리 데이터 소개 2
        • (5강) 원시 데이터의 수집과 가공
        • 오피스아워 (11.10, 수)
        • (6강) 데이터 구축 작업 설계
        • (7강) 데이터 구축 가이드라인 작성 기초
        • (8강) 관계 추출 과제의 이해
        • (9강) 관계 추출 관련 논문 읽기
        • (10강) 관계 추출 데이터 구축 실습
      • [P Stage] - 모델 최적화
        • (1강) 최적화 소개 및 강의 개요
        • (2강) 대회 및 데이터셋 소개
        • (3강) 작은 모델, 좋은 파라미터 찾기: AutoML 이론
        • 🔨(4강) 작은 모델, 좋은 파라미터 찾기: AutoML 실습
        • (5강) 작은 모델, 좋은 파라미터 찾기: Data Augmentation & AutoML 결과 분석
        • 🔨오피스아워 -Baseline 코드에 모듈 작성하기(신종선 멘토님)
      • [P Stage] - Product Serving
        • Part 1: Product Serving 개론
          • 1.1 강의 진행 방식
          • 1.2 MLOps 개론
          • 1.3 Model Serving
          • 1.4 머신러닝 프로젝트 라이프 사이클
        • Part 2: 프로토타입부터 점진적으로 개선하기
          • 2.1 프로토타이핑 - Notebook 베이스(Voila)
          • 2.2 프로토타이핑 - 웹 서비스 형태(Streamlit)
          • 2.3 Linux & Shell Command
          • 2.4 Cloud
          • 2.5 Github Action을 활용한 CI/CD
        • Part 3: 더 완성화된 제품으로
          • 3.1.1 FastAPI
          • 3.1.2 Fast API
          • 3.1.3 Fast API
          • 3.2 Docker
          • 3.3 Logging
          • 3.4 MLFlow
        • Part 4: 심화 소재
          • 4.1 BentoML
          • 4.2 Airflow
          • 4.3 머신러닝 디자인 패턴
          • 4.4 앞으로 더 공부하면 좋을 내용
      • 특강
        • (특강) 김상훈 - 캐글 그랜드마스터의 노하우 대방출
        • (특강) 이활석 - 서비스 향 AI 모델 개발하기
        • (특강) 구종만 - AI + ML과 Quant Trading
        • (특강) 문지형 - 내가 만든 AI 모델은 합법일까, 불법일까
        • (특강) 이준엽 - Full Stack ML Engineer
        • (특강) 박은정 - AI 시대의 커리어 빌딩
        • (특강) 오혜연 - AI Ethics
    • Competition
      • (DACON)한국어 문장 관계 분류 경진대회
        • Day1(2.14, 월)
        • Day2(2.15, 화)
        • Day3(2.16, 수)
        • Day4(2.17, 목)
      • 2021 인공지능 데이터 활용 경진대회
        • 역량평가
          • Day1 (9.28, 화)
          • Day2 (9.29, 수)
          • Day3 (9.30, 목)
        • 예선
          • Data 분석
          • NSML
          • What We Have Done?
    • ETC
      • 인터뷰 대비
        • Computer Science
        • ML/DL
      • Poetry로 dependency 관리
        • window에서 설치하기
      • code block
      • 공부할 것 임시보관
      • Transformer to T5
      • Hugging Face Tutorial
        • Ch1. Transformer models
        • Ch2. Using Transformers
        • Ch3. Fine-tuning a model with the Trainer API
      • KLUE
      • Pandas
  • TIL : Ops
    • AWS
      • SageMaker
  • TIL : Computer (CS)
    • Error
      • TextEncodeInput must be Union[TextInputSequence, Tuple[InputSequence, InputSequence]]
    • Algorithm
      • Theory
      • Programmers
        • 기능개발
    • ETC
      • Github 커밋 히스토리 삭제
Powered by GitBook
On this page
  • 1. LSTM (Long Short-Term Memory)
  • 1.1. Basic Structure
  • 2. GRU (Gated Recurrent Unit)
  • 3. Backpropagation in LSTM&GRU
  • 4. Summary
  • 관련코드 Link

Was this helpful?

  1. TIL : ML
  2. Boostcamp
  3. [U Stage] - NLP

(04강) LSTM and GRU

Previous(03강) Recurrent Neural Network and Language ModelingNext(05강) Sequence to Sequence with Attention

Last updated 3 years ago

Was this helpful?

LSTM, GRU에 대해서 알아보고 기존 RNN과의 차의를 알아보자

Further Reading

Further Question

  • BPTT 이외에 RNN/LSTM/GRU의 구조를 유지하면서 gradient vanishing/exploding 문제를 완화할 수 있는 방법이 있을까요?

  • RNN/LSTM/GRU 기반의 Language Model에서 초반 time step의 정보를 전달하기 어려운 점을 완화할 수 있는 방법이 있을까요?

※ 기존 RNN이 가진 문제점

  • 현재노드와 먼 과거의 상태를 사용한 문맥처리가 어렵다.

  • 거리가 멀어짐에 따라 Gradient vanishing/exploding 현상이 발생한다.

1. LSTM (Long Short-Term Memory)

  • Pass cell state information straightly without any transformation

  • Short-Term memory(단기기억)을 길게 가져간다는 의미

1.1. Basic Structure

  • i : input gate, whether to write to cell

  • f : forget gate, whether to erase cell

  • o : output gate, how much to reveal cell

  • g : gate gate, how much to write to cell

Forget Gate

Gate Gate (Input Gate)

  • Generate information to be added and cut it by input gate

  • Generate new cell state by adding cureent information to previous cell state

Output Gate

  • Generate gidden state by passing cell state to tanh and output gate

  • Pass this hidden state to next time step, and output or next layer if needed

2. GRU (Gated Recurrent Unit)

LSTM의 모델을 경량화한 모델

적은 메모리 요구량과 빠른 계산이 가능하도록 하였다. LSTM에는 Cell State와 Hidden State가 있는 반면 GRU에는 Hidden State 만이 존재한다.

  • forget gate를 1 - input gate 가중치로 사용

3. Backpropagation in LSTM&GRU

  • 필요로 하는 정보를 곱셈이 아닌 덧셈연산으로 이루어지게되어 RNN에 비해 길이에 대해 Gradient Vanishing, exploding 문제를 완화할수 있게 되었다.

4. Summary

관련코드 Link

LSTM은 위 그림과같이 기존 RNN의 input값인 xt,htx_t, h_txt​,ht​뿐만 아니라 Cell State라는 ctc_tct​값도 Input으로 가지게된다. 이 ctc_tct​값은 지금까지 지나온 layer들 즉, 과거의 단어에 대한 정보를 잘 담고 있다.

ft=σ(Wf ⋅ [ht−1,xt]+bf)f_t = \sigma(W_f\ \cdot \ [h_{t-1}, x_t] + b_f)ft​=σ(Wf​ ⋅ [ht−1​,xt​]+bf​)

과거로부터 넘어온 데이터에서 wfw_fwf​만큼 가중치를 제거한다.(생략할 부분을 정한다.)

it=σ(Wf⋅[ht−1,xt]+bf)i_t = \sigma(W_f \cdot [h_{t-1}, x_t] + b_f)it​=σ(Wf​⋅[ht−1​,xt​]+bf​)

C~=tanh(Wc⋅[ht−1,xt]+bc)\widetilde{C} = tanh(W_c \cdot [h_{t-1}, x_t]+b_c)C=tanh(Wc​⋅[ht−1​,xt​]+bc​)

Ct=ft⋅Ct−1+it⋅C~tC_t = f_t \cdot C{t-1} + i_t \cdot \widetilde{C}_tCt​=ft​⋅Ct−1+it​⋅Ct​

ot=σ(Wo[ht−1,xt]+bo)o_t = \sigma(W_o[h_{t-1}, x_t] + b_o)ot​=σ(Wo​[ht−1​,xt​]+bo​)

ht=ot⋅tanh(Ct)h_t = o_t \cdot tanh(C_t)ht​=ot​⋅tanh(Ct​)

zt=σ(Wz⋅[ht−1,xt])z_t = \sigma(W_z \cdot [h_{t-1}, x_t])zt​=σ(Wz​⋅[ht−1​,xt​])

rt=σ(Wr⋅[ht−1,xt])r_t = \sigma(W_r \cdot [h_{t-1}, x_t])rt​=σ(Wr​⋅[ht−1​,xt​])

ht~=tanh(W⋅[rt⋅ht−1,xt])\widetilde{h_t} = tanh(W \cdot [r_t \cdot h_{t-1}, x_t])ht​​=tanh(W⋅[rt​⋅ht−1​,xt​])

ht=(1−zt)⋅ht−1+zt⋅ht~h_t = (1-z_t)\cdot h_{t-1} + z_t \cdot \widetilde{h_t}ht​=(1−zt​)⋅ht−1​+zt​⋅ht​​ 🌟가중치의 합이 1이 되게끔 되어있다.

c.f) Ct=ft⋅Ct−1+it⋅Ct~C_t = f_t \cdot C_{t-1} + i_t \cdot \widetilde{C_t}Ct​=ft​⋅Ct−1​+it​⋅Ct​​ in LSTM

CtC_tCt​를 사용하지 않고 hth_tht​를 사용

Understanding LSTM Networks
Logo4_fancy_rnn.ipynbGoogle Docs