SlideShare a Scribd company logo
Natural Language Processing
Word2Vec Algorithm
연세대학교 전기전자공학부
영상 및 비디오 패턴인식 연구실
이형민
minimonia@yonsei.ac.kr
What is Natural Language Processing(NLP)?
Computer Science
Artificial
Intelligence Linguistics
NLP
Goal: Understanding and representing the meaning of language
What is Natural Language Processing(NLP)?
Feature Extraction of a Word
How in Image Processing??
“From the Pixel Data”
How about NLP??
Feature Extraction of a Word
How can we extract feature from a word??
By Spelling???
Compliment
Complement Praise
How can we extract feature from a word??
The WordNet Project
• 프린스턴 대학교에서 진행된 대규모 ‘Word Database’ 프로젝트
• 각 단어들의 상하관계, 유의어 관계 등을 전부 수동으로 정리
• ‘ImageNet’ 의 전신
The WordNet Project
The WordNet Project
Problems…
• 의미는 비슷하지만, 같은 맥락에서 쓰이지 않는 단어들이 존재한다.
ex) Good ≒ Skillful
 The weather is good! ≠ The weather is skillful!
• 신조어가 탄생하면, 추가하기가 쉽지 않다.
• 주관적이다.
• ‘동의어다.’ or ‘동의어가 아니다.’ 와 같이 극단적인 관계 정의로 인해 각
단어가 얼마나 비슷한지 등의 정도를 나타내기가 애매하다.
One – Hot Vector Representation
• 단어를 벡터로써 표현하려는 첫번째 시도
• 다른 성분들은 전부 0이고, 한 성분만 1인 벡터로 단어 하나를 표현한다.
• 하지만, 단어 간의 유사성을 측정하는 것이 불가능하다.
“Representing a word with its Surroundings”
“Representing a word with its Surroundings”
• Full Document: 그 단어를 포함하는 문서 전체를 활용
• Windows: 중심 단어 주변 몇 개의 단어만을 활용
Cooccurence Matrix
• 중심 단어를 기준으로, 좌우의 m개의 단어 중 어떤 단어가 몇 번 등장하는
지를 Count.
• ‘Symmetric Matrix’가 된다.
• Example:
 I like deep learning.
 I like NLP
 I enjoy flying
Cooccurence Matrix
 I like deep learning.
 I like NLP
 I enjoy flying
Cooccurence Matrix
Problem…
• 단어의 수가 많아질수록, 차원이 급격하게 늘어난다  메모리 문제 발생
 PCA
 Singular Value Decomposition(SVD)
Cooccurence Matrix
With SVD
Cooccurence Matrix
With SVD
Cooccurence Matrix
Problems with SVD
• 시간 복잡도가 매우 높다:
• 새로운 단어를 추가하기가 어렵다.
높은 차원의 벡터를 줄일 것이 아니라, 처음부터 낮은 차원의
벡터를 만들자!
 Rumelhart, David E., Geoffrey E. Hinton, and Ronald J. Williams. "Learning
representations by back-propagating errors." Cognitive modeling 5.3 (1988): 1.
 Bengio, Yoshua, et al. "A neural probabilistic language model." Journal of machine
learning research 3.Feb (2003): 1137-1155.
 Collobert, Ronan, et al. "Natural language processing (almost) from scratch." Journal
of Machine Learning Research 12.Aug (2011): 2493-2537.
 Mikolov, Tomas, et al. "Distributed representations of words and phrases and their
compositionality." Advances in neural information processing systems. 2013.
중심 단어를 이용하여 주변 단어를 예측!  Word2Vec
• 일반적인 딥러닝 알고리즘과 마찬가지로, 목적함수(Obejctive Function)를
정의한 후, Gradient Decent 등의 방법으로 최적화한다.
:고정된 중심 단어 에 대하여, 그 주변에 가 존재할 확률
P(나는 고양이를 좋아한다) > P(나는 고양이를 강아지)
Word2Vec: Fundamentals
• 즉, 중심 단어의 input vector와 주변 단어의 output vector의 correlation이
극대화 되는 방향으로 Optimization이 진행된다.
• 기본적으로 한 단어에 대응하는 벡터는 2개씩 존재한다.
• v: Input Vector  중심 단어로서, 주변 단어를 예측할 때 쓰이는 vector
• u: Output Vector  주변 단어로서, 중심단어로부터 예측 당할 때 쓰이는 vector
Word2Vec: Fundamentals
왜 Vector가 2개인가?
• 단어 하나에 대응하는 벡터가 한 가지 밖에 없다면??
 나는 서울에 거주한다.
 그의 거주지는 서울이다.
 서울 거주민이 증가하는 추세다.
중심 단어 ‘거주’ 주변에는
‘서울’이 많이 등장한다.
거주
‘거주’와 ‘서울’에 해당하는 Vector의 거리가 가까워지는 방향으로
학습이 진행된다.
서울
거주 ≒ 서울 ????
Word2Vec: Fundamentals
• 문제를 해결하기 위해 ‘중심 단어’로서 역할을 할 때와 ‘주변 단어’로서
역할을 할 때의 벡터를 다르게 설정한다. 앞의 식을 다시 살펴 보자.
• v: Input Vector  중심 단어로서 역할을 할 때 쓰이는 Vector
• u: Output Vector  주변 단어로서 역할을 할 때 쓰이는 Vector
• 즉, 중심 단어의 input vector 가 fix 되었을 때, 주변 단어들의 output
vector 를 와 가까운 위치가 되도록 배치한다.
Word2Vec: Fundamentals
거주
서울
부산
 나는 서울에 거주한다.
 그의 거주지는 서울이다.
 서울 거주민이 증가하는 추세다.
 나는 부산에 거주한다.
 그의 거주지는 부산이다.
 부산 거주민이 증가하는 추세다.
Input Vector (v)
Output Vector (u)
Word2Vec: Fundamentals
서울
부산
 나는 서울에 거주한다.
 그의 거주지는 서울이다.
 서울 거주민이 증가하는 추세다.
 나는 부산에 거주한다.
 그의 거주지는 부산이다.
 부산 거주민이 증가하는 추세다.
Input Vector (v)
Output Vector (u)
부산 ≒ 서울
• 정리하자면, 주변 단어들의 분포가 유사하면 유사한 의미의 단어가
되게끔 학습을 한 것이다.
• 결국, 각 단어들이 단어가 갖는 의미에 따라 좌표 공간상에 벡터로서
표현되도록 할 수 있게 되었다.
Word2Vec: Fundamentals
Word2Vec: Details
• Word2Vec 알고리즘 종류
• 계산 속도 향상을 위한 추가 학습방법
 CBOW
 Skip – Gram Model
 Negative Sampling
 Hierarchical Softmax
Continuous Bag of Words Model (CBOW)
• 주변 단어들로부터 중심 단어를 예측하는 DNN 알고리즘
 Database 내의 총 단어 수: W
 중심 단어를 예측하기 위해 참고할 주변 단어 수: C
 Hidden Layer의 Node 수(우리가 설정해줘야 한다): N
…{W{
C
N W
주변 단어들의
One-Hot Vector
Network Output Vector
중심 단어의 One-Hot Vector와 비교
+ 평균
Word Vector
학습
Continuous Bag of Words Model (CBOW)
Loss Function
Skip-Gram Model
… }W
{
C
NW
• 중심 단어로부터 주변 단어들을 예측해내는 알고리즘
 Database 내의 총 단어 수: W
 중심 단어를 예측하기 위해 참고할 주변 단어 수: C
 Hidden Layer의 Node 수(우리가 설정해줘야 한다): N
Network Output Vector
주변 단어들의 One-Hot Vector와 비교
중심 단어의
One-Hot Vector
학습
Skip-Gram Model
Loss Function
Word Vector Examples
Glove Visualizations: Company - CEO
Word Vector Examples
Glove Visualizations: Superlatives
Word Vector Examples
Korean Word2Vec Demo
http://w.elnn.kr/search/
한국
서울
일본
도쿄
서울 - 한국 = 도쿄 - 일본
한국 – 서울 + 일본 = 도쿄
Application in Image Processing
Radford, Alec, Luke Metz, and Soumith Chintala. "Unsupervised representation learning with deep convolutional generative adversarial
networks." arXiv preprint arXiv:1511.06434 (2015).
SmilingNeutral
Man
Woman Smiling Woman
Neutral Woman
Neutral Man
Smiling Man
Latent Vector
Application in Image Processing
Radford, Alec, Luke Metz, and Soumith Chintala. "Unsupervised representation learning with deep convolutional generative adversarial
networks." arXiv preprint arXiv:1511.06434 (2015).
Application in Image Processing
Image Captioning
Thank You!!
Any Questions??

More Related Content

PPTX
Kubernetes Security
PDF
Introduction to Bootstrap
PPTX
Nodejs Session01
PPTX
JavaScript
PPTX
An Intro into webpack
PPTX
Docker introduction
PPTX
React event
PDF
VueJS Best Practices
Kubernetes Security
Introduction to Bootstrap
Nodejs Session01
JavaScript
An Intro into webpack
Docker introduction
React event
VueJS Best Practices

What's hot (20)

PDF
Kubernetes
PDF
Introduction to kotlin coroutines
PPTX
Docker introduction for the beginners
PDF
NextJS, A JavaScript Framework for building next generation SPA
PDF
Intro To MongoDB
PDF
Kubernetes - Security Journey
PPTX
Getting started with Docker
PPTX
Introduction to Angularjs
PDF
CSS3 Media Queries
PPTX
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
PPT
JavaScript - An Introduction
PDF
Javascript basics
PPTX
HTML Semantic Elements
PPTX
ASP.NET Core MVC + Web API with Overview
PPTX
Microservices with Minimal APi and .NET 6
PPTX
Introduction to Docker
PPTX
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
PDF
Introduction to CSS3
PPTX
Basic Concept of Node.js & NPM
PDF
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Kubernetes
Introduction to kotlin coroutines
Docker introduction for the beginners
NextJS, A JavaScript Framework for building next generation SPA
Intro To MongoDB
Kubernetes - Security Journey
Getting started with Docker
Introduction to Angularjs
CSS3 Media Queries
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
JavaScript - An Introduction
Javascript basics
HTML Semantic Elements
ASP.NET Core MVC + Web API with Overview
Microservices with Minimal APi and .NET 6
Introduction to Docker
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
Introduction to CSS3
Basic Concept of Node.js & NPM
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Ad

Similar to Word 2 Vec Algorithm (20)

PPTX
Brief hystory of NLP and Word2Vec
PDF
Context2Vec 기반 단어 의미 중의성 해소, Word Sense Disambiguation
PDF
[싸이그램즈 2018] 텍스트 데이터 전처리로 시작하는 NLP
PDF
자연어4 | 1차강의
PPTX
From A Neural Probalistic Language Model to Word2vec
PPTX
Nlp word2vec
PDF
230112_word2vec1_논문리뷰.pdf
PPTX
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
PDF
GloVe:Global vectors for word representation
PDF
파이썬을 활용한 자연어 분석
PDF
파이썬과 자연어 4 | word/doc2vec
PPTX
머신러닝의 자연어 처리기술(I)
PDF
Natural Language Processing(NLP) - Basic
PPTX
Word2Vec 개요 및 활용
PDF
Spam text message filtering by using sen2 vec and feedforward neural network
PDF
MultiModal Embedding integrates various data types, like images, text, and au...
PDF
230223_word2vec2_논문리뷰.pdf
PDF
서울 R&D 캠퍼스 자연어 수업자료
PDF
Facebook Meta's technical direction in Large Language Models (LLMs)
PDF
Compressing neural language models by sparse word representation
Brief hystory of NLP and Word2Vec
Context2Vec 기반 단어 의미 중의성 해소, Word Sense Disambiguation
[싸이그램즈 2018] 텍스트 데이터 전처리로 시작하는 NLP
자연어4 | 1차강의
From A Neural Probalistic Language Model to Word2vec
Nlp word2vec
230112_word2vec1_논문리뷰.pdf
(Kor ver.)NLP embedding(word2vec) tutorial & implementation(Tensorflow)
GloVe:Global vectors for word representation
파이썬을 활용한 자연어 분석
파이썬과 자연어 4 | word/doc2vec
머신러닝의 자연어 처리기술(I)
Natural Language Processing(NLP) - Basic
Word2Vec 개요 및 활용
Spam text message filtering by using sen2 vec and feedforward neural network
MultiModal Embedding integrates various data types, like images, text, and au...
230223_word2vec2_논문리뷰.pdf
서울 R&D 캠퍼스 자연어 수업자료
Facebook Meta's technical direction in Large Language Models (LLMs)
Compressing neural language models by sparse word representation
Ad

More from Hyeongmin Lee (20)

PDF
PR-455: CoTracker: It is Better to Track Together
PDF
PR-430: CLIP4Clip: An Empirical Study of CLIP for End to End Video Clip Retri...
PDF
PR-420: Scalable Model Compression by Entropy Penalized Reparameterization
PDF
PR-409: Denoising Diffusion Probabilistic Models
PDF
PR-395: Variational Image Compression with a Scale Hyperprior
PDF
PR-386: Light Field Networks: Neural Scene Representations with Single-Evalua...
PDF
PR-376: Softmax Splatting for Video Frame Interpolation
PDF
PR-365: Fast object detection in compressed video
PDF
PR-340: DVC: An End-to-end Deep Video Compression Framework
PDF
PR-328: End-to-End Optimized Image Compression
PDF
PR-315: Taming Transformers for High-Resolution Image Synthesis
PDF
PR-302: NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis
PDF
PR-278: RAFT: Recurrent All-Pairs Field Transforms for Optical Flow
PDF
PDF
PR-252: Making Convolutional Networks Shift-Invariant Again
PDF
PR-240: Modulating Image Restoration with Continual Levels via Adaptive Featu...
PDF
PR-228: Geonet: Unsupervised learning of dense depth, optical flow and camera...
PDF
PR-214: FlowNet: Learning Optical Flow with Convolutional Networks
PDF
[PR12] Making Convolutional Networks Shift-Invariant Again
PPTX
Latest Frame interpolation Algorithms
PR-455: CoTracker: It is Better to Track Together
PR-430: CLIP4Clip: An Empirical Study of CLIP for End to End Video Clip Retri...
PR-420: Scalable Model Compression by Entropy Penalized Reparameterization
PR-409: Denoising Diffusion Probabilistic Models
PR-395: Variational Image Compression with a Scale Hyperprior
PR-386: Light Field Networks: Neural Scene Representations with Single-Evalua...
PR-376: Softmax Splatting for Video Frame Interpolation
PR-365: Fast object detection in compressed video
PR-340: DVC: An End-to-end Deep Video Compression Framework
PR-328: End-to-End Optimized Image Compression
PR-315: Taming Transformers for High-Resolution Image Synthesis
PR-302: NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis
PR-278: RAFT: Recurrent All-Pairs Field Transforms for Optical Flow
PR-252: Making Convolutional Networks Shift-Invariant Again
PR-240: Modulating Image Restoration with Continual Levels via Adaptive Featu...
PR-228: Geonet: Unsupervised learning of dense depth, optical flow and camera...
PR-214: FlowNet: Learning Optical Flow with Convolutional Networks
[PR12] Making Convolutional Networks Shift-Invariant Again
Latest Frame interpolation Algorithms

Word 2 Vec Algorithm

  • 1. Natural Language Processing Word2Vec Algorithm 연세대학교 전기전자공학부 영상 및 비디오 패턴인식 연구실 이형민 minimonia@yonsei.ac.kr
  • 2. What is Natural Language Processing(NLP)?
  • 3. Computer Science Artificial Intelligence Linguistics NLP Goal: Understanding and representing the meaning of language What is Natural Language Processing(NLP)?
  • 4. Feature Extraction of a Word How in Image Processing?? “From the Pixel Data”
  • 5. How about NLP?? Feature Extraction of a Word
  • 6. How can we extract feature from a word??
  • 7. By Spelling??? Compliment Complement Praise How can we extract feature from a word??
  • 8. The WordNet Project • 프린스턴 대학교에서 진행된 대규모 ‘Word Database’ 프로젝트 • 각 단어들의 상하관계, 유의어 관계 등을 전부 수동으로 정리 • ‘ImageNet’ 의 전신
  • 10. The WordNet Project Problems… • 의미는 비슷하지만, 같은 맥락에서 쓰이지 않는 단어들이 존재한다. ex) Good ≒ Skillful  The weather is good! ≠ The weather is skillful! • 신조어가 탄생하면, 추가하기가 쉽지 않다. • 주관적이다. • ‘동의어다.’ or ‘동의어가 아니다.’ 와 같이 극단적인 관계 정의로 인해 각 단어가 얼마나 비슷한지 등의 정도를 나타내기가 애매하다.
  • 11. One – Hot Vector Representation • 단어를 벡터로써 표현하려는 첫번째 시도 • 다른 성분들은 전부 0이고, 한 성분만 1인 벡터로 단어 하나를 표현한다. • 하지만, 단어 간의 유사성을 측정하는 것이 불가능하다.
  • 12. “Representing a word with its Surroundings”
  • 13. “Representing a word with its Surroundings” • Full Document: 그 단어를 포함하는 문서 전체를 활용 • Windows: 중심 단어 주변 몇 개의 단어만을 활용
  • 14. Cooccurence Matrix • 중심 단어를 기준으로, 좌우의 m개의 단어 중 어떤 단어가 몇 번 등장하는 지를 Count. • ‘Symmetric Matrix’가 된다. • Example:  I like deep learning.  I like NLP  I enjoy flying
  • 15. Cooccurence Matrix  I like deep learning.  I like NLP  I enjoy flying
  • 16. Cooccurence Matrix Problem… • 단어의 수가 많아질수록, 차원이 급격하게 늘어난다  메모리 문제 발생  PCA  Singular Value Decomposition(SVD)
  • 19. Cooccurence Matrix Problems with SVD • 시간 복잡도가 매우 높다: • 새로운 단어를 추가하기가 어렵다. 높은 차원의 벡터를 줄일 것이 아니라, 처음부터 낮은 차원의 벡터를 만들자!  Rumelhart, David E., Geoffrey E. Hinton, and Ronald J. Williams. "Learning representations by back-propagating errors." Cognitive modeling 5.3 (1988): 1.  Bengio, Yoshua, et al. "A neural probabilistic language model." Journal of machine learning research 3.Feb (2003): 1137-1155.  Collobert, Ronan, et al. "Natural language processing (almost) from scratch." Journal of Machine Learning Research 12.Aug (2011): 2493-2537.  Mikolov, Tomas, et al. "Distributed representations of words and phrases and their compositionality." Advances in neural information processing systems. 2013. 중심 단어를 이용하여 주변 단어를 예측!  Word2Vec
  • 20. • 일반적인 딥러닝 알고리즘과 마찬가지로, 목적함수(Obejctive Function)를 정의한 후, Gradient Decent 등의 방법으로 최적화한다. :고정된 중심 단어 에 대하여, 그 주변에 가 존재할 확률 P(나는 고양이를 좋아한다) > P(나는 고양이를 강아지) Word2Vec: Fundamentals
  • 21. • 즉, 중심 단어의 input vector와 주변 단어의 output vector의 correlation이 극대화 되는 방향으로 Optimization이 진행된다. • 기본적으로 한 단어에 대응하는 벡터는 2개씩 존재한다. • v: Input Vector  중심 단어로서, 주변 단어를 예측할 때 쓰이는 vector • u: Output Vector  주변 단어로서, 중심단어로부터 예측 당할 때 쓰이는 vector Word2Vec: Fundamentals
  • 22. 왜 Vector가 2개인가? • 단어 하나에 대응하는 벡터가 한 가지 밖에 없다면??  나는 서울에 거주한다.  그의 거주지는 서울이다.  서울 거주민이 증가하는 추세다. 중심 단어 ‘거주’ 주변에는 ‘서울’이 많이 등장한다. 거주 ‘거주’와 ‘서울’에 해당하는 Vector의 거리가 가까워지는 방향으로 학습이 진행된다. 서울 거주 ≒ 서울 ???? Word2Vec: Fundamentals
  • 23. • 문제를 해결하기 위해 ‘중심 단어’로서 역할을 할 때와 ‘주변 단어’로서 역할을 할 때의 벡터를 다르게 설정한다. 앞의 식을 다시 살펴 보자. • v: Input Vector  중심 단어로서 역할을 할 때 쓰이는 Vector • u: Output Vector  주변 단어로서 역할을 할 때 쓰이는 Vector • 즉, 중심 단어의 input vector 가 fix 되었을 때, 주변 단어들의 output vector 를 와 가까운 위치가 되도록 배치한다. Word2Vec: Fundamentals
  • 24. 거주 서울 부산  나는 서울에 거주한다.  그의 거주지는 서울이다.  서울 거주민이 증가하는 추세다.  나는 부산에 거주한다.  그의 거주지는 부산이다.  부산 거주민이 증가하는 추세다. Input Vector (v) Output Vector (u) Word2Vec: Fundamentals
  • 25. 서울 부산  나는 서울에 거주한다.  그의 거주지는 서울이다.  서울 거주민이 증가하는 추세다.  나는 부산에 거주한다.  그의 거주지는 부산이다.  부산 거주민이 증가하는 추세다. Input Vector (v) Output Vector (u) 부산 ≒ 서울 • 정리하자면, 주변 단어들의 분포가 유사하면 유사한 의미의 단어가 되게끔 학습을 한 것이다. • 결국, 각 단어들이 단어가 갖는 의미에 따라 좌표 공간상에 벡터로서 표현되도록 할 수 있게 되었다. Word2Vec: Fundamentals
  • 26. Word2Vec: Details • Word2Vec 알고리즘 종류 • 계산 속도 향상을 위한 추가 학습방법  CBOW  Skip – Gram Model  Negative Sampling  Hierarchical Softmax
  • 27. Continuous Bag of Words Model (CBOW) • 주변 단어들로부터 중심 단어를 예측하는 DNN 알고리즘  Database 내의 총 단어 수: W  중심 단어를 예측하기 위해 참고할 주변 단어 수: C  Hidden Layer의 Node 수(우리가 설정해줘야 한다): N …{W{ C N W 주변 단어들의 One-Hot Vector Network Output Vector 중심 단어의 One-Hot Vector와 비교 + 평균 Word Vector 학습
  • 28. Continuous Bag of Words Model (CBOW) Loss Function
  • 29. Skip-Gram Model … }W { C NW • 중심 단어로부터 주변 단어들을 예측해내는 알고리즘  Database 내의 총 단어 수: W  중심 단어를 예측하기 위해 참고할 주변 단어 수: C  Hidden Layer의 Node 수(우리가 설정해줘야 한다): N Network Output Vector 주변 단어들의 One-Hot Vector와 비교 중심 단어의 One-Hot Vector 학습
  • 31. Word Vector Examples Glove Visualizations: Company - CEO
  • 32. Word Vector Examples Glove Visualizations: Superlatives
  • 33. Word Vector Examples Korean Word2Vec Demo http://w.elnn.kr/search/ 한국 서울 일본 도쿄 서울 - 한국 = 도쿄 - 일본 한국 – 서울 + 일본 = 도쿄
  • 34. Application in Image Processing Radford, Alec, Luke Metz, and Soumith Chintala. "Unsupervised representation learning with deep convolutional generative adversarial networks." arXiv preprint arXiv:1511.06434 (2015). SmilingNeutral Man Woman Smiling Woman Neutral Woman Neutral Man Smiling Man Latent Vector
  • 35. Application in Image Processing Radford, Alec, Luke Metz, and Soumith Chintala. "Unsupervised representation learning with deep convolutional generative adversarial networks." arXiv preprint arXiv:1511.06434 (2015).
  • 36. Application in Image Processing Image Captioning