Compare commits

...

4 Commits

Author SHA1 Message Date
higepi 7cad55116c corr 2.1 2 years ago
higepi ac5f8433e0 corr 2 2 years ago
higepi 0ed986773b cor 2 years ago
higepi dca0ea72fc cor 2 years ago

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -0,0 +1 @@
<mxfile host="Electron" modified="2022-10-06T15:02:13.549Z" agent="5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.4.2 Chrome/87.0.4280.141 Electron/11.3.0 Safari/537.36" etag="PWQyYY0R317QYA6qE_LZ" version="14.4.2" type="device"><diagram id="c8k1S_rz-XqTnCVLnYee" name="Page-1">7VnbbuIwEP2aPIKce3gstGy12gtSV9ruo5uYxCsnzjoGQr9+7dghN1rBtgWxAlUlM/aceM6MxxcMe5aWnxjMk680QsSwQFQa9q1hWRPgiv9SsVUKz7eUImY4UiqzUTzgZ6SVQGtXOEJFpyOnlHCcd5UhzTIU8o4OMkY33W5LSrpvzWGMBoqHEJKh9ieOeKK0geU3+nuE46R+s+lNVEsK684aokhgRDdKVTln3xn2jFHK1VNazhCR3NW8KAbmL7TuBsZQxg8xWIRxMR19G43u6SP4XCx+zBffRzoYa0hW2mE9WL6tGUBZdCOJFFJIYFHg0LCnCU+JUJjiURmgaMBjMzBz565IE0RTxNlWdNk0hLo63EmLy1rHEIEcr7vwUMc13sHt3rCgWLzYAjoFbU/j6Ax0AOhCFHTFQqSt2gT2gFyzB2T2gDhkMeIDIPHQcrtRVfE5Ilb2NVYHx6oPZPeBPjhWzjVWB8fKCnpAwWljZdqD2DC6yiIkjYCIBGU8oTHNIPlCaa7D8xtxvtXrFVxx2g0eKjF/lObjSaDFX5Uolj8l3pYavRK2tZAJX5QhsGpZWdo7uTGtpG0LaIEYFnwg1u7RV0awSCrnjkkzwU8Vz1eI9PT6XIXrlX7B/rQ9OB87CXBstL0DZiYhYnshhOkmwRw95LByeyM2ON0owyJXe44lLiWh0yUmZEYJZRWQbU4AmM93JK8R46g8djaX9fRyuhVNL/ft2W7tme0W+CAigxMS6c/fkcheubHdMxNpetf68y71x/QPLEDmWStQPcyLK0GW/8KKf7aZc6k1yHa8LpP2uZmcDJhMaJqiAZ3CZ97jjeA4k5tY4buc4lPJDBYn6BvdkOIokuZThgr8DJ8qKFkHcrmjqzxxp4Z7K7FEIStUTTPfiemgt2zuyVnvlEzXwC2ml+h/YNrx3C7Te3J633Hk45g2B0znMIcXT7TVP9sGQ6KdkxI9vEVKYQqzi2fatnples9W8bTFw92z4HlEkrqk1Zm6Ydv7s6J1w0jxciM6mCAvm0bxFKtvR/65szUKDX+6NnyJAFO5RmZPRV51ARUu0OUKjKTXapEA2l6P5Yk1uEojvFUDrNWXnhlBLzO8YWaYp02N6yniny7L3ngLJnZuY3fS+nTTwvLHk2HrsTdkTuCPxWZ79zH7VWkMhq1vvj0TYvPrhOre/MRj3/0F</diagram></mxfile>

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@ -255,15 +255,6 @@
"source": [
"print(wv.doesnt_match(['wood', 'oak', 'tree', 'iron', 'leaf']))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(wv.most_similar(positive=['The largest country is']))"
]
}
],
"metadata": {

@ -1,4 +1,9 @@
import gensim.downloader as api
from sklearn.decomposition import IncrementalPCA # inital reduction
from sklearn.manifold import TSNE # final reduction
import numpy as np # array handling
wv = api.load('word2vec-google-news-300')
# Affichage de quelques mots du vocabulaire
@ -17,4 +22,62 @@ vec_woman = wv['woman']
result = wv.most_similar(positive=(vec_father - vec_man + vec_woman), topn=1)
print(result)
print(wv.most_similar(positive=['The largest country is']))
## Visualisation
def reduce_dimensions(model):
num_dimensions = 2 # final num dimensions (2D, 3D, etc)
# extract the words & their vectors, as numpy arrays
vectors = np.asarray(model.wv.vectors)
labels = np.asarray(model.wv.index_to_key) # fixed-width numpy strings
# reduce using t-SNE
tsne = TSNE(n_components=num_dimensions, random_state=0)
vectors = tsne.fit_transform(vectors)
x_vals = [v[0] for v in vectors]
y_vals = [v[1] for v in vectors]
return x_vals, y_vals, labels
x_vals, y_vals, labels = reduce_dimensions(model)
def plot_with_plotly(x_vals, y_vals, labels, plot_in_notebook=True):
from plotly.offline import init_notebook_mode, iplot, plot
import plotly.graph_objs as go
trace = go.Scatter(x=x_vals, y=y_vals, mode='text', text=labels)
data = [trace]
if plot_in_notebook:
init_notebook_mode(connected=True)
iplot(data, filename='word-embedding-plot')
else:
plot(data, filename='word-embedding-plot.html')
def plot_with_matplotlib(x_vals, y_vals, labels):
import matplotlib.pyplot as plt
import random
random.seed(0)
plt.figure(figsize=(12, 12))
plt.scatter(x_vals, y_vals)
#
# Label randomly subsampled 25 data points
#
indices = list(range(len(labels)))
selected_indices = random.sample(indices, 25)
for i in selected_indices:
plt.annotate(labels[i], (x_vals[i], y_vals[i]))
try:
get_ipython()
except Exception:
plot_function = plot_with_matplotlib
else:
plot_function = plot_with_plotly
plot_function(x_vals, y_vals, labels)

Loading…
Cancel
Save