ROKO

[coursera] Sequence Models: Week 2 본문

Artificial Intelligence/Deep Learning

[coursera] Sequence Models: Week 2

RO_KO 2024. 7. 9. 14:42
728x90

1-hot representation

1-hot representation은 각 단어를 구분하기에는 좋지만 단어간의 유사성을 유지하기는 어렵다. 

 

Featured representation: word embedding

각 차원마다 특징을 기준으로 학습하도록 할 수 있다면 더 풍부한 표현을 가진 word vector가 생길 것이다.

word vector를 시각화한 3D 공간을 보면 비슷한 단어들끼리 뭉쳐있다.

 

Transfer learning and word embeddings

  1. Learn word embeddings from large text corpus
  2. Transfer embedding to new task with smaller training set
  3. Optional: Continue to finetune the word embeddings with new data

번역과 같은 task를 제외한 대부분 nlp task들은 많은 양의 데이터로 학습된 word embedding에 적당히 적은 양의 training set으로 transfer learning이 가능하다.

 

Properties of word embeddings

학습된 word embedding들끼리 semantic 연산이 가능하다. king \(\rightarrow\) man : ? \(\rightarrow\) woman에서 ?의 단어를 구하고 싶다면 \(e_w = max sim(e_w, e_{king}-e_{man}+e_{woman})\)을 구하면 된다. similarity function으로는 cosine similarity를 사용한다.

 

Word embedding

Vocab size가 5인 word vector를 학습했다고 가정하자. 학습한 이후의 word vector들을 embedding matrix라고 한다. word embedding matrix를 사용하는 방법은 5개의 단어중 뽑고자하는 단어의 index를 1-hot vector로 표현해 embedding matrix와 곱하면 그 단어벡터가 있는 행의 벡터만 추출된다.

 

CBOW (Continuous Bag Of the Words)

context word를 가지고 target word를 예측하는 방식이다.

Skip-grams

target word를 가지고 양쪽에 있는 context word를 예측하는 language modeling으로 word representation을 학습한다. context word 길이가 n인 경우 skip n-gram이라고 한다. n개의 weights가 필요하다.

 

vocab size가 10000이라고 가정했을때 softmax로부터 나오는 과정은 많은 연산 때문에 학습시간이 느려지게 된다. vocab size의 확장성을 고려했을때 더욱이 느려진다는것을 고려할때 좋지 않은 방법이다.

 

Hierarchical softmax

10000개의 확률을 계산할 필요 없이 이진트리를 이용해 computational cost를 낮출 수 있다.

 

How to sample the context c?

context를 sampling하는 과정은 학습에 중요하다. uniform 하게 sampling할 경우 관사같은 빈번한 단어들이 주로 선택되고 각 단어들은 단어간의 의 유사성이 아닌 관사에 의해 의미가 부여될 수 있다. 

 

Negative sampling

target word와 context word를 positive 관계로 보고 vocab에서 random으로 selection한 word를 negative로 보아 contrastive learning을 하는 방법이다.

10000개의 softmax를 계산하는것보다 이진분류 10000 개를 하는게 더 빠르고 효율적이다.

 

GloVe (Global Vectors for word representation)

discrete representation인 LSA나 dense representation word2vec 모두 서로의 장점이 서로의 단점으로 여겨진다. 단어간의 semantic 정보를 비교할 수 있게 학습하면서 전체 통계기반의 정보도 나타내기 위한 방법으로 GloVe가 소개 되었다. 목적은 각 벡터의 내적 값이 전체 corpus에서 co-occurance value와 같게 만드는 것이다.

 

Sentiment classification

sentence sentiment classification 경우, 문장에서 각 단어의 word embedding을 평균한 뒤 softmax를 통해 ratings을 예측 할 수 있다. 하지만 이는 문장내의 단어 순서를 무시하는 방식이므로 긍정 혹은 부정 단어의 빈도에 의존하게 된다.

RNN의 many-to-one 구조를 이용한다면 단어의 어순을 고려할 수 있게 되어 이전 방식의 단점을 해결 할 수 있다.

 

Debiasing word embeddings

word embedding을 학습하는 과정에서 데이터의 분포에 의해 bias된 feature를 학습할 수 있다.

728x90
Comments