forked from IntuitionEngineeringTeam/chars2vec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_usage.py
32 lines (24 loc) · 1.06 KB
/
example_usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import chars2vec
import sklearn.decomposition
import matplotlib.pyplot as plt
# Load Inutition Engineering pretrained model
# Models names: 'eng_50', 'eng_100', 'eng_150', 'eng_200', 'eng_300'
c2v_model = chars2vec.load_model('eng_50')
words = ['Natural', 'Language', 'Understanding',
'Naturael', 'Longuge', 'Updderctundjing',
'Motural', 'Lamnguoge', 'Understaating',
'Naturrow', 'Laguage', 'Unddertandink',
'Nattural', 'Languagge', 'Umderstoneding']
# Create word embeddings
word_embeddings = c2v_model.vectorize_words(words)
# Project embeddings on plane using the PCA
projection_2d = sklearn.decomposition.PCA(n_components=2).fit_transform(word_embeddings)
# Draw words on plane
f = plt.figure(figsize=(8, 6))
for j in range(len(projection_2d)):
plt.scatter(projection_2d[j, 0], projection_2d[j, 1],
marker=('$' + words[j] + '$'),
s=500 * len(words[j]), label=j,
facecolors='green' if words[j]
in ['Natural', 'Language', 'Understanding'] else 'black')
plt.show()