forked from Kyubyong/wordvectors
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mariusz Woloszyn
committed
Sep 4, 2017
1 parent
c13be14
commit fe3a0c2
Showing
1 changed file
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Using TensorFlow backend.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import gensim\n", | ||
"\n", | ||
"# Load pre-trained Word2Vec model.\n", | ||
"model = gensim.models.KeyedVectors.load('data/pl.bin')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('królowa', 0.6799831390380859),\n", | ||
" ('cesarzowa', 0.6074954867362976),\n", | ||
" ('księżniczka', 0.5475618839263916),\n", | ||
" ('księżna', 0.5279887318611145),\n", | ||
" ('waza', 0.5248866081237793),\n", | ||
" ('konstancja', 0.5197093486785889),\n", | ||
" ('królową', 0.5182099938392639),\n", | ||
" ('dama', 0.5130698084831238),\n", | ||
" ('elżbieta', 0.5102220773696899),\n", | ||
" ('króla', 0.5050344467163086)]" | ||
] | ||
}, | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"model.most_similar(positive=['kobieta', 'król'], negative=['mężczyzna'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('królowa', 0.9603520631790161),\n", | ||
" ('cesarzowa', 0.9171873331069946),\n", | ||
" ('księżniczka', 0.8568219542503357),\n", | ||
" ('elżbieta', 0.8513852953910828),\n", | ||
" ('księżna', 0.8503665924072266),\n", | ||
" ('konstancja', 0.8395503759384155),\n", | ||
" ('inkwizycja', 0.834706723690033),\n", | ||
" ('dynastia', 0.8325018882751465),\n", | ||
" ('królową', 0.828750491142273),\n", | ||
" ('izabela', 0.8216117024421692)]" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"model.most_similar_cosmul(positive=['kobieta', 'król'], negative=['mężczyzna'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('wyjść', 0.8666046261787415),\n", | ||
" ('ruszyć', 0.8621427416801453),\n", | ||
" ('wylądować', 0.856998860836029),\n", | ||
" ('zejść', 0.856095552444458),\n", | ||
" ('zamieszkać', 0.8547601699829102),\n", | ||
" ('wyruszyć', 0.8522873520851135),\n", | ||
" ('przejść', 0.846845805644989),\n", | ||
" ('uderzyć', 0.846382200717926),\n", | ||
" ('zaatakować', 0.8440034985542297),\n", | ||
" ('stanąć', 0.8418554663658142)]" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"model.most_similar_cosmul(positive=['otworzyć', 'wejść'], negative=['włączyć'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 30, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"%config InlineBackend.figure_format = 'retina'\n", | ||
"\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"from sklearn.manifold import TSNE\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# viz_words = 500\n", | ||
"# tsne = TSNE()\n", | ||
"# embed_tsne = tsne.fit_transform(embed_mat[:viz_words, :])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# fig, ax = plt.subplots(figsize=(14, 14))\n", | ||
"# for idx in range(viz_words):\n", | ||
"# plt.scatter(*embed_tsne[idx, :], color='steelblue')\n", | ||
"# plt.annotate(int_to_vocab[idx], (embed_tsne[idx, 0], embed_tsne[idx, 1]), alpha=0.7)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python [conda env:py3]", | ||
"language": "python", | ||
"name": "conda-env-py3-py" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |