juooo1117

Word Embeddings - word2vec, Skip-Gram Model 본문

Artificial Intelligence

Word Embeddings - word2vec, Skip-Gram Model

Hyo__ni 2023. 12. 14. 20:46

Word Embeddings

하나의 차원에 표현되었던 각 단어를 연속적인 숫자를 값으로 갖는 벡터 형식으로 표현하는 방식

Word2Vec : 하나의 단어를 표현하는 벡터를 구하기 위해 주변 단어를 활용해서 학습한다.

 

Skip-Gram Model

skip gram neural network architecture for Word2Vec

'The'가 입력으로 들어갔을 때, 주변의 단어(output)를 맞추는 것  ⇒  quick 

Model details

  -  input word를 one-hot vector 로 표현한다.

  -  This vector will have 10,000 components (one for every word in our vocabulary) and we’ll place a “1” in the position corresponding to the word “ants”, and 0s in all of the other positions.

  -  There is no activation function on the hidden layer neurons, but the output neurons use softmax.

  -  when evaluate the trained network on an input word, the output vector will actually be a probability distribution (i.e., a bunch of floating point values, not a one-hot vector)

word2vec with tensorflow

  • bag-of-words 모델: 주변의 단어를 바탕으로 중간 단어를 예측. context는 현재(중간) 단어의 앞과 뒤의 몇몇 단어로 구성되어 있으며, 이 아키텍처는 콘텍스트의 단어 순서가 중요하지 않기 때문에 bag-of-words 모델이라고 불린다.
  • skip-gram 모델: 동일한 문장 내의 현재 단어의 앞과 뒤 일정 범위 내의 단어를 예측한다. 즉, 단어 자체가 주어지면 단어의 context(또는 주변)을 예측하는 것이다. 

두 가지 방법 중에서 skip-gram 접근 방식을 사용해서 tensorflow를 이용해서 코드로 구현해 보자

 

[Practice - tensorflow 'word2vec' tutorial]

https://github.com/juooo1117/practice_AI_Learning/blob/main/word2vec_Skip_GramModel.ipynb