A good representation is one that makes a subsequent learning task easier.
워드 임베딩
워드 임베딩 개요
Representation
- 데이터를 어떻게 표현하는가에 따라 해결하는 문제의 난이도가 달라 질 수 있다
전통적인 단어 표현방법 (Word Representation)
단어백 (Bag-of-Word)
A vector with one 1 and a lot of zeroes
“one-hot” representation / 1-of-V coding / Discrete representation
Simple and easy to implement
벡터의 차원 = |전체 사전의 크기|
단어간의 유사도 (one-hot encoding)
고양이 = (0,0,0,1,….,0,0,0)
강아지 = (0,0,1,0,…,0,0,0)
Similarity (“고양이”, “강아지”) = 0
Distributed Semantics
분포가설 (Distributional hypothesis)
= 한 단어의 뜻은 그 단어가 이웃하고 있는 단어들로 유추할 수 있다.
문맥정보(Context)를 사용하여 단어를 표현
문맥정보 어디서부터 어디까지?
= How to make co-occurrence matrix
단어-문서 행렬
Term-document matrix
단어-단어 행렬
Term-term matrix (or word-word co-occurrence matrix)
Term-document matrix
Word-word co-occurrence matrix
= 문맥정보를 문서 대신 주변 단어로 줄여보자
Sliding window (symmetric)
I like deep learning
I like NLP
I enjoy flying
워드임베딩 (Word embedding)
Word-word co-occurrence matrix의 문제점
• 단어가 늘어날 수록 차원이 커진다
• 저장 공간이 많이 필요
• 희소한 벡터 (sparse representation)
- 워드 임베딩 (Word embedding)
• 중요한 정보만 남기고 적은 차원에서 단어를 표현하고 싶다!
• 기계학습에서 자질로 사용할 때 처리하기 쉽다는 장점
단어 ➔ d-차원 실수 벡터 (real-value dense vector)
• 50~300 차원 내에서 단어를 표현
• d << |Vocabulary|
Predictive-Based(예측기반으로 단어를 얻어냄)
- 단어에서 문맥을 예측
- 문맥에서 단어를 예측
word2vec (Skip-gram, CBOW)
word2vec 알고리즘
Continuous bag-of-word / Skip-gram
Predict a word given its bag-ofwords context (CBOW)
Predict a context word (position-independent) from the center word (Skip-gram)
CBOW 학습용 데이터셋
- CBOW는 context words(주변 단어)를 입력으로 받아서 center word(중심 단어)를 예측하는 방법
- 슬라이딩 윈도우 방식으로 학습을 위한 데이터셋을 구축(비지도 학습)
예문 “The fat cat sat on the mat”
Skip-gram 학습용 데이터셋
Skip-gram - context words
예문1: The quick brown fox jumps over the lazy dog.
- window size가 2일 때 context word는 왼쪽으로 2단어, 오른쪽으로 2단어
예문2: “우리는 아침식사로 오렌지 주스와 크로와상을 주문했다
예문3: “우리는 아침식사로 사과 주스와 크로와상을 주문했다
- ‘사과’는 ‘오렌지’와 유사한 컨텍스트에 나타난다 → 유사한 단어 벡터를 가진다
- Input word가 오렌지이고, window size = 2일 때
(input word, context word)
➔ (오렌지, 우리)
➔ (오렌지, 아침식사)
➔ (오렌지, 주스)
➔ (오렌지, 크로와상)
가중치 행렬 → 단어 임베딩벡터
Vocabulary : 10,000 단어
- 단어벡터의차원: 300
- 가중치행렬= 단어벡터의lookup table
- 예)V(Vocabulary) = 5일때
Word Analogy
= 벡터공간에서 유사한 단어들은 가깝게 분포
Linear relationships in Word2vec
Word analogies test
= 벡터들의 연산으로 테스트할 수 있음
워드임베딩에 담긴 정보
ex) “king”의 vector representation
[ 0.50451 , 0.68607 , -0.59517 , -0.022801, 0.60046 , -0.13498 , -0.08813 , 0.47377 , -0.61798 , -0.31012 , -0.076666, 1.493 , -0.034189, - 0.98173 , 0.68229 , 0.81722 , -0.51874 , -0.31503 , -0.55809 , 0.66421 , 0.1961 , -0.13495 , -0.11476 , -0.30344 , 0.41177 , -2.223 , -1.0756 , - 1.0783 , -0.34354 , 0.33505 , 1.9927 , -0.04234 , -0.64319 , 0.71125 , 0.49159 , 0.16754 , 0.34344 , -0.25663 , -0.8523 , 0.1661 , 0.40102 , 1.1685 , -1.0137 , -0.21585 , -0.15155 , 0.78321 , -0.91241 , -1.6106 , -0.64426 , -0.51042 ]
“woman” and “girl” are similar to each other in a lot of places. The same with “man” and“boy”
“boy” and “girl” also have places where they are similar to each other, but different from
“woman” or “man”. Could these be coding for a vague conception of youth?
“water” – showing the differences between categories. You can, for example, see that blue column going all the way down and stopping before the embedding for “water”.
분산표현 (Distributed Representation)
• Distributed representation of concepts is representations composed of many elements that can be set separately from each other
• Distributed representations are powerful because they can use
n features with k values to describe k n different concepts
피처가 n개가 있으면 k의 n제곱개의 단어를 표현할 수 있다.
Word2vec 평가
Task-based evaluation
(좋은 단어 벡터를 사용하면 NLP task의 성능을개선)
• 개체명 인식
• 질의 응답 시스템
Intrinsic evaluation
• 단어 간 유사성에 대한 모델의 판단과 human 판단을 비교
• WordSim353: 353 noun pairs rated 0~10
• TOEFL multiple-choice vocabulary tests
Word analogy task
단어 유추 게임
: capital-common-countries
• 도쿄 : 일본 = 파리 : ? ➔ 프랑스
: capital-world
• 방콕 : 타이 = 베를린 : ? ➔ 독일
: currency
• 유럽 : 유로 = 베트남 : ? ➔ 동
: city-in-state
• 어바인 : 캘리포니아 = 시카고 : ? ➔ 일리노이
: family
• 아버지 : 어머니 = 할아버지 : ? ➔ 할머니
word2vec을 활용할 수 있는 분야
1. Data augmentation - 학습데이터를 증량시키는 기법
= Methods to generate more data for model training
• Thesaurus
• Word Embeddings
예) ‘오렌지’ 위치에 ‘바나나’, ‘사과’ 등 다른 과일명을넣어 변형된 문장 생성을 시도해 볼 수 있음
Back Translation (번역문을 다시 번역하여 데이터 늘리기)
• To generate more training data to improve translation model performance
• Translating target language to source language and
mixing both original source sentence and back-translated sentence to train a model.
Contextualized Word Embeddings
2. recommendation (추천)
ex) AirBnB’s Similar Listings (2018)
• Embedding-based solution leads to a 21% increase in Similar Listing carousel CTR
• 4.9% more guests discovering the listing ended up booking in the Similar Listing carouse
참조
word2vec 관련 이론 정리
예전에 포스팅한 Kaggle ‘What’s Cooking?’ 대회에서 word2vec 기술을 살짝 응용해서 사용해볼 기회가 있었다. 그 이후에도 word2vec이 쓰일만한 토픽들을 접하면서 이쪽에 대해 공부를 해보다가, 기존
shuuki4.wordpress.com
'KT-Aivle School (AI) > 딥러닝' 카테고리의 다른 글
[언어지능 딥러닝] RNN for NLP (1) | 2022.10.08 |
---|---|
[언어지능 딥러닝] CNN for NLP (1) | 2022.10.07 |
[언어지능 딥러닝] 텍스트 마이닝 (0) | 2022.10.05 |
[언어지능 딥러닝] NLP (자연어 처리) (2) | 2022.10.04 |
[Computer Vision] Object Detection (0) | 2022.09.23 |