Word Embeddings
Unit 2, Module 2.4
1
First 10 minutes for studying~
Quiz on Word Embeddings :)
2
Warm Up:
3
What is an “apple”?
What is a “monarch”?
What’s going on here?
Play Semantris
How does the computer know�which words are related?
4
Play Blocks version
How does the computer know which
words are related?
5
Discussion
6
| Gender | Age |
man | 1 | 7 |
woman | | |
boy | | |
girl | 9 | 2 |
Fill in the missing Feature values
7
| Gender | Age |
man | 1 | 7 |
woman | 9 | 7 |
boy | 1 | 2 |
girl | 9 | 2 |
grandfather | | |
adult | | |
child | | |
infant | | |
Fill in the missing values
8
| Gender | Age |
man | 1 | 7 |
woman | 9 | 7 |
boy | 1 | 2 |
girl | 9 | 2 |
grandfather | 1 | 9 |
adult | 5 | 7 |
child | 5 | 2 |
infant | 5 | 1 |
9
How would you represent:�
More Semantic Dimensions
How would you represent king, queen prince, and princess?
We need another semantic dimension.
What would you call it?
10
11
| Gender | Age | Royalty |
man | 1 | 7 | 1 |
woman | 9 | 7 | 1 |
boy | 1 | 2 | 1 |
girl | 9 | 2 | 1 |
king | 1 | 8 | 8 |
queen | 9 | 7 | 8 |
prince | 1 | 2 | 8 |
princess | 9 | 2 | 8 |
monarch | | | |
12
| Gender | Age | Royalty |
man | 1 | 7 | 1 |
woman | 9 | 7 | 1 |
boy | 1 | 2 | 1 |
girl | 9 | 2 | 1 |
king | 1 | 8 | 8 |
queen | 9 | 7 | 8 |
prince | 1 | 2 | 8 |
princess | 9 | 2 | 8 |
monarch | 5 | 7 | 8 |
Semantic Distance
Is “boy” closer to “girl” or to “queen”?
How can we measure the distance?
13
| Gender | Age | Royalty |
man | 1 | 7 | 1 |
woman | 9 | 7 | 1 |
boy | 1 | 2 | 1 |
girl | 9 | 2 | 1 |
king | 1 | 8 | 8 |
queen | 9 | 7 | 8 |
prince | 1 | 2 | 8 |
princess | 9 | 2 | 8 |
14
| Gender | Age |
man | 1 | 7 |
woman | 9 | 7 |
boy | 1 | 2 |
girl | 9 | 2 |
Pythagorean theorem
8
5
√(82 + 52) = 9.43
The distance from boy to woman is 9.43
Measure distance between points using the Pythagorean theorem:
Remember Semantris
To do what Semantris does, we can select a clue word and measure the distances from our clue to the target words in the blocks.
The target word with the smallest distance should be selected.
Our chosen target: Pasta (red block)
Our clue word: Macaroni
Note another target word might have a smaller distance and be selected instead, e.g., Cheese (blue block) might be chosen because “macaroni and cheese” is a common phrase.
15
Remember Semantris
Using multiple words as clues: We can average the clue words together and measure the distance from the average to each of the target words.
Our chosen target: Pasta
Clue words: Macaroni, Spaghetti, Linguini, Italian.
16
What other types of reasoning could a computer do using semantic feature space?
17
Lots of stuff!
18
How Google understands the questions you ask it.
Translating between languages
Summarizing an online article
Writing a fictional story
Solving analogy problems
Analogies
“Man” is to “king” as “woman” is to .
19
AnalogY - A comparison between two things based on their relationships.
Analogies
“Man” is to “king” as “woman” is to queen .
20
Can we use semantic features to solve this problem?
21
This is what you were doing inside your head:
Woman is to queen as…
Man is to___________
Girl is to ___________
Boy is to ___________
What is “king” - “man” ?
22
| Gender | Age | Royalty |
king | 1 | 8 | 8 |
man | 1 | 7 | 1 |
king - man | 0 | 1 | 7 |
red arrow
What is “king” - “man” + “woman” ?
23
| Gender | Age | Royalty |
king | 1 | 8 | 8 |
man | 1 | 7 | 1 |
king - man | 0 | 1 | 7 |
woman | 9 | 7 | 1 |
+ woman | 9 | 8 | 8 |
queen | 9 | 7 | 8 |
red arrow
green arrow
Try it:
24
“woman” is to “girl” as�“king” is to ______.
Draw the red and green arrows.
Try it:
25
“woman” is to “girl” as�“king” is to prince .
Try it #2:
26
“boy” is to “king” as�“prince” is to ______.
Draw the red and green arrows.
“woman” is to “girl” as “king” is to ______.
27
| Gender | Age | Royalty |
girl | 9 | 2 | 1 |
woman | 9 | 7 | 1 |
girl - woman | | | |
king | 1 | 8 | 8 |
+ king | | | |
Answer: ____________ | | | |
Directions: Use the table to look up the feature values and compute the answer.
green arrow
red arrow
How many dimensions do we need?
How would you represent “father”, “uncle”, “sister”, “cousin”?
What dimension would you add to help you represent “cucumber”?
Your Answer: __________________________
What dimension would you add to help you represent “smile”? Or “honesty”?
Your Answer:__________________________
We need many more dimensions. Can we get the computer to help us?
Word embeddings: type of word representation that allows words with similar meaning to have a similar representation
28
How are word embeddings created?
Start with lots of text. For each word, pay attention to which words occur before it and after it. Create features that capture these statistics.
29
were | visiting | the | king | in | his | palace |
reported | to | the | queen | in | her | palace |
●●●
●●●
●●●
●●●
30
feature
A 300
Dimensional word embedding used in the online “WordEmbeddingDemo”.
Introduction to Dave’s Word Embedding Demos
& Student Activities
31
Introduction to the 3D Semantic Space
Try It: 3D Semantic Space
32
Watch It
Word Embedding Demo, Part 1 (3:37)
Introduction to the Feature Vector Display
Try it: Vector Visualization
33
Watch It
Word Embedding Demo, Part 2 (2:56)
Introduction to Analogies
Try it: Analogies
34
Watch It
Take away
Real AI systems use word embeddings�
35
36
Exit Ticket
Explain: How does the computer know which words are related?
37
Limitations
38
Christina - turn into pictures - These were some other notes we had in the Unit 2 Overview Table
39