[NLP] Word Embedding - CBOW

2023. 3. 27. 15:11
๐Ÿง‘๐Ÿป‍๐Ÿ’ป ์ฃผ์š” ์ •๋ฆฌ
 
NLP
Word Embedding
CBOW

 

 

Represent the meaning of word

 

  • Two basic neural network models:
    • Continuous Bag of Word(CBOW) : use a window of word to predict the middle word.
    • Skip-gram (SG) : use a word to predict the surrounbding ones in window.

 

 

 

์œ„์™€ ๊ฐ™์€ ์ฐจ์ด๋ฅผ ๋ณด์ž…๋‹ˆ๋‹ค.

 

 

ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ด…์‹œ๋‹ค.

 

 

 

 

CBOW (Continuous Bag of Word)

 

"The cat sat on floor" ์ด๋ผ๋Š” ๋ฌธ์žฅ์ด ์žˆ๋‹ค๊ณ  ํ•ฉ์‹œ๋‹ค.

 

์ด ๋ฌธ์žฅ์„ CBOW ๋ฐฉ์‹์œผ๋กœ Window size = 2๋กœ ํ•™์Šต์„ ์‹œํ‚ค๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

๋‹ค์Œ์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์œ„์™€ ๊ฐ™์ด ๊ฐ€์šด๋ฐ ๋‹จ์–ด ํ•˜๋‚˜๋ฅผ ์ œ์™ธํ•œ ์–‘์ชฝ ๋‘ ๊ฐœ์”ฉ(window size๋งŒํผ)์˜ ๋‹จ์–ด๋ฅผ input์œผ๋กœ ์ฃผ๊ณ  output์„ ๊ฐ€์šด๋ฐ ๋‹จ์–ด๊ฐ€ ๋˜๋„๋ก ํ•™์Šต ์‹œํ‚ต๋‹ˆ๋‹ค.

 

 

 

 

์ด ํ˜•ํƒœ๋กœ ๋‹ค์‹œ ์‚ดํŽด๋ด…์‹œ๋‹ค.

 

๊ฐ ๋‹จ์–ด๋“ค์„ one-hot encoding์„ ๊ฑฐ์ณ one-hot vector๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

 

์ฆ‰, ๋ฌธ์žฅ์„ Neural Network ํ˜•ํƒœ๋กœ ๋ฐ”๊พผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

 

๊ทธ๋ฆฌ๊ณ  ๋‹ค์‹œ,

 

 

๊ฐ๊ฐ์˜ ๋‹จ์–ด๋“ค์„ input์— ๋Œ€ํ•ด์„œ hidden layer ์—ฐ์‚ฐ์„ ํ•˜์—ฌ output layer์—์„œ "sat"์˜ vector๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.

 

 

๊ทธ๋ฆฌ๊ณ ,

 

input์˜ one-hot vector๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด, hidden layer๋ฅผ ๊ฑฐ์ณ์„œ "sat"์ด๋ผ๋Š” ๋‹จ์–ด์˜ word embedding ๊ณผ์ •์„ ๊ฑฐ์นฉ๋‹ˆ๋‹ค.

 

 

 

๊ทธ๋ฆฌ๊ณ , ์•„๋ž˜์™€ ๊ฐ™์ด

 

The cat ___.

 

___์— ๋“ค์–ด๊ฐ€๋Š” sat, eat, sit, is ,... ๋“ฑ์˜ ๋‹จ์–ด๋Š” ๋น„์Šทํ•˜๊ฒŒ ํ•™์Šต ๋˜์–ด ๋น„์Šทํ•œ ๊ณต๊ฐ„์— mapping ๋˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

 

 

 

We can consider either W or W’ as the word’s representation. Or even take the average.

 

 

 

๊ฒฐ๊ตญ, ๊ฐ€์šด๋ฐ t ๋ฒˆ์งธ ์ธ๋ฑ์Šค์˜ ๋‹จ์–ด๋ฅผ ๊ฐ€์ง€๊ณ , t - 2, t - 1, t + 1, t + 2๋ฒˆ์งธ ์ธ๋ฑ์Šค์˜ ๋‹จ์–ด๋“ค์„ ํ•™์Šตํ•˜๋Š” ํ˜•์‹์ž…๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

 

 

'Artificial Intelligence > Natural Language Processing' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[NLP] Word Embedding - Word2Vec  (0) 2023.03.27
[NLP] Word Embedding - Skip Gram  (0) 2023.03.27
[NLP] Introduction to Word Embedding  (0) 2023.03.26
[NLP] Overview NLP  (0) 2023.03.21
[NLP] Introduction to NLP  (0) 2023.03.21

BELATED ARTICLES

more