Processing math: 100%

ABOUT ME

Today
Yesterday
Total
  • 2. RNN & LSTM & GRU
    NLP/1주차 2021. 9. 7. 11:44

    sequential data와 이전 hidden state를 입력으로 현재 time step의 출력을 내는 구조.

    • h(t1) : old hidden state vector
    • xt : input vector at some time step
    • ht : new hidden state vector
    • fW : RNN function with params W
    • yt : output vector at time step t

    Types of RNNs

    • one-to-one
    • one-to-many: image captioning
    • many-to-one: sentiment classification
    • many-to-many: machine translation, video classification on frame level

    RNN have vanishing/exploding gradient problems


    LSTM (Long Short-Term Memory)

    https://colah.github.io/posts/2015-08-Understanding-LSTMs/

     

    Understanding LSTM Networks -- colah's blog

    Posted on August 27, 2015 Humans don’t start their thinking from scratch every second. As you read this essay, you understand each word based on your understanding of previous words. You don’t throw everything away and start thinking

    colah.github.io

    LSTM Cell

    Sigmoid: 원래 가지던 값의 일부를 보존 (0 ~ 1 사이기 때문)

     

    LSTM의 네개의 gate의는 cell state간 information의 flow량을 결정한다. 

    • Forget Gate: 이전 정보 중 일부만 보존한다.

    • Gate Gate: 

     

    Generate Information to be added and cut it by input gate
    Generate new cell state by adding current information to previous cell state

    Ct: 기억해야할 모든 정보를 보존

    ht: 현재 time step의 예측값에 직접적인 정보만을 담음

     

    GRU (Gated Recurrent Unit)

    • LSTM을 경량화. hidden state vector만 존재
    • forget gate와 input gate로 만들어지던 cell state를 1zt , zt로 변경 -> 가중 평균의 형태로 계산

     

    LSTM과 GRU 모두 덧셈으로 정보를 만들어주기 때문에 gradient를 큰 변형 없이 전달할 수 있어서 long-term dependency 문제를 해결.


    실습 / 과제

    • nn.Embedding(): 파이토치에서 임베딩 층을 만들어 임베딩 벡터를 학습하는데 사용됨
    • 두개의 인자 num_embeddings과 embedding_dim을 사용
      • num_embeddings : 임베딩을 할 단어들의 개수. 다시 말해 단어 집합의 크기입니다.
      • embedding_dim : 임베딩 할 벡터의 차원입니다. 사용자가 정해주는 하이퍼파라미터입니다.
      • padding_idx : 선택적으로 사용하는 인자입니다. 패딩을 위한 토큰의 인덱스를 알려줍니다.
    • packed_padded_sequence
    [참고] https://wikidocs.net/64779 
    https://pytorch.org/docs/stable/generated/torch.nn.utils.rnn.pack_padded_sequence.html

    'NLP > 1주차' 카테고리의 다른 글

    4. NMT를 위한 전처리  (0) 2021.09.10
    3. Seq2Seq & Beam search  (0) 2021.09.08
    1. NLP intro & BOW & Word Embedding  (0) 2021.09.06

    댓글

Designed by Tistory.