{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pretrained word2vec\n",
    "\n",
    "You can download Malaya pretrained without need to import malaya.\n",
    "\n",
    "#### word2vec from local news\n",
    "\n",
    "[size-256](https://github.com/huseinzol05/Malaya/tree/master/pretrained-model/wordvector#download)\n",
    "\n",
    "#### word2vec from wikipedia\n",
    "\n",
    "[size-256](https://github.com/huseinzol05/Malaya/tree/master/pretrained-model/wordvector#download)\n",
    "\n",
    "#### word2vec from local social media\n",
    "\n",
    "[size-256](https://github.com/huseinzol05/Malaya/tree/master/pretrained-model/wordvector#download)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But If you don't know what to do with malaya word2vec, Malaya provided some useful functions for you!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 4.21 s, sys: 793 ms, total: 5 s\n",
      "Wall time: 4.11 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "import malaya\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load malaya news word2vec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "vocab_news, embedded_news = malaya.wordvector.load_news()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load malaya wikipedia word2vec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "vocab_wiki, embedded_wiki = malaya.wordvector.load_wiki()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load word vector interface\n",
    "\n",
    "```python\n",
    "\n",
    "def load(embed_matrix, dictionary):\n",
    "\n",
    "    \"\"\"\n",
    "    Return malaya.wordvector._wordvector object.\n",
    "\n",
    "    Parameters\n",
    "    ----------\n",
    "    embed_matrix: numpy array\n",
    "    dictionary: dictionary\n",
    "\n",
    "    Returns\n",
    "    -------\n",
    "    _wordvector: malaya.wordvector._wordvector object\n",
    "    \"\"\"\n",
    "    \n",
    "```\n",
    "\n",
    "1. `embed_matrix` must be a 2d,\n",
    "\n",
    "```python\n",
    "\n",
    "array([[ 0.25      , -0.10816103, -0.19881412, ...,  0.40432587,\n",
    "         0.19388093, -0.07062137],\n",
    "       [ 0.3231817 , -0.01318745, -0.17950962, ...,  0.25      ,\n",
    "         0.08444146, -0.11705721],\n",
    "       [ 0.29103908, -0.16274083, -0.20255531, ...,  0.25      ,\n",
    "         0.06253044, -0.16404966],\n",
    "       ...,\n",
    "       [ 0.21346697,  0.12686132, -0.4029543 , ...,  0.43466234,\n",
    "         0.20910986, -0.32219803],\n",
    "       [ 0.2372157 ,  0.32420087, -0.28036436, ...,  0.2894639 ,\n",
    "         0.20745888, -0.30600077],\n",
    "       [ 0.27907744,  0.35755727, -0.34932107, ...,  0.37472805,\n",
    "         0.42045262, -0.21725406]], dtype=float32)\n",
    "```\n",
    "\n",
    "2. `dictionary`, a dictionary mapped `{'word': 0}`,\n",
    "\n",
    "```python\n",
    "\n",
    "{'mengembanfkan': 394623,\n",
    " 'dipujanya': 234554,\n",
    " 'comicolor': 182282,\n",
    " 'immaz': 538660,\n",
    " 'qabar': 585119,\n",
    " 'phidippus': 180802,\n",
    "}\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Load custom word vector\n",
    "\n",
    "Like fast-text, example, I download from here, https://dl.fbaipublicfiles.com/fasttext/vectors-wiki/wiki.ms.vec\n",
    "\n",
    "We need to parse the data to get `embed_matrix` and `dictionary`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import io\n",
    "import numpy as np\n",
    "\n",
    "fin = io.open('wiki.ms.vec', 'r', encoding='utf-8', newline='\\n', errors='ignore')\n",
    "n, d = map(int, fin.readline().split())\n",
    "\n",
    "data, vectors = {}, []\n",
    "for no, line in enumerate(fin):\n",
    "    tokens = line.rstrip().split(' ')\n",
    "    data[tokens[0]] = no\n",
    "    vectors.append(list(map(float, tokens[1:])))\n",
    "    \n",
    "vectors = np.array(vectors)\n",
    "fast_text = malaya.wordvector.load(vectors, data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /Users/huseinzolkepli/Documents/Malaya/malaya/wordvector.py:94: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
      "\n",
      "WARNING:tensorflow:From /Users/huseinzolkepli/Documents/Malaya/malaya/wordvector.py:105: The name tf.InteractiveSession is deprecated. Please use tf.compat.v1.InteractiveSession instead.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "word_vector_news = malaya.wordvector.load(embedded_news, vocab_news)\n",
    "word_vector_wiki = malaya.wordvector.load(embedded_wiki, vocab_wiki)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check top-k similar semantics based on a word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Embedding layer: 8 closest words to: 'anwar' using malaya news word2vec\n",
      "[['najib', 0.6967672109603882], ['mukhriz', 0.675892174243927], ['azmin', 0.6686884164810181], ['rafizi', 0.6465028524398804], ['muhyiddin', 0.6413404941558838], ['daim', 0.6334482431411743], ['khairuddin', 0.6300410032272339], ['shahidan', 0.6269811391830444]]\n"
     ]
    }
   ],
   "source": [
    "word = 'anwar'\n",
    "print(\"Embedding layer: 8 closest words to: '%s' using malaya news word2vec\"%(word))\n",
    "print(word_vector_news.n_closest(word=word, num_closest=8, metric='cosine'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Embedding layer: 8 closest words to: 'anwar' using malaya wiki word2vec\n",
      "[['rasulullah', 0.6918460130691528], ['jamal', 0.6604709029197693], ['noraniza', 0.65153968334198], ['khalid', 0.6450133323669434], ['mahathir', 0.6447468400001526], ['sukarno', 0.641593337059021], ['wahid', 0.6359774470329285], ['pekin', 0.6262176036834717]]\n"
     ]
    }
   ],
   "source": [
    "word = 'anwar'\n",
    "print(\"Embedding layer: 8 closest words to: '%s' using malaya wiki word2vec\"%(word))\n",
    "print(word_vector_wiki.n_closest(word=word, num_closest=8, metric='cosine'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check batch top-k similar semantics based on a word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['anwar',\n",
       "  'najib',\n",
       "  'mukhriz',\n",
       "  'azmin',\n",
       "  'rafizi',\n",
       "  'muhyiddin',\n",
       "  'daim',\n",
       "  'khairuddin'],\n",
       " ['mahathir',\n",
       "  'daim',\n",
       "  'sahruddin',\n",
       "  'streram',\n",
       "  'morsi',\n",
       "  'anifah',\n",
       "  'jokowi',\n",
       "  'ramasamy']]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "words = ['anwar', 'mahathir']\n",
    "word_vector_news.batch_n_closest(words, num_closest=8,\n",
    "                                 return_similarity=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What happen if a word not in the dictionary?\n",
    "\n",
    "You can set parameter `soft` to `True` or `False`. Default is `True`.\n",
    "\n",
    "if `True`, a word not in the dictionary will be replaced with nearest JaroWrinkler ratio.\n",
    "\n",
    "if `False`, it will throw an exception if a word not in the dictionary."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "ename": "Exception",
     "evalue": "husein-comel not in dictionary, please use another word or set `soft` = True",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-14-50a78d59e7a9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mwords\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'anwar'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'mahathir'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'husein-comel'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m word_vector_wiki.batch_n_closest(words, num_closest=8,\n\u001b[0;32m----> 3\u001b[0;31m                                  return_similarity=False,soft=False)\n\u001b[0m",
      "\u001b[0;32m~/Documents/Malaya/malaya/wordvector.py\u001b[0m in \u001b[0;36mbatch_n_closest\u001b[0;34m(self, words, num_closest, return_similarity, soft)\u001b[0m\n\u001b[1;32m    484\u001b[0m                     raise Exception(\n\u001b[1;32m    485\u001b[0m                         \u001b[0;34m'%s not in dictionary, please use another word or set `soft` = True'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 486\u001b[0;31m                         \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mwords\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    487\u001b[0m                     )\n\u001b[1;32m    488\u001b[0m         \u001b[0mbatches\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_vector_by_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mw\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mwords\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mException\u001b[0m: husein-comel not in dictionary, please use another word or set `soft` = True"
     ]
    }
   ],
   "source": [
    "words = ['anwar', 'mahathir','husein-comel']\n",
    "word_vector_wiki.batch_n_closest(words, num_closest=8,\n",
    "                                 return_similarity=False,soft=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['anwar',\n",
       "  'rasulullah',\n",
       "  'jamal',\n",
       "  'noraniza',\n",
       "  'khalid',\n",
       "  'mahathir',\n",
       "  'sukarno',\n",
       "  'wahid'],\n",
       " ['mahathir',\n",
       "  'anwar',\n",
       "  'wahid',\n",
       "  'najib',\n",
       "  'khalid',\n",
       "  'sukarno',\n",
       "  'suharto',\n",
       "  'salahuddin'],\n",
       " ['husein',\n",
       "  'khairi',\n",
       "  'gccsa',\n",
       "  'jkrte',\n",
       "  'montagny',\n",
       "  'pejudo',\n",
       "  'badriyyin',\n",
       "  'naginatajutsu']]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "words = ['anwar', 'mahathir','husein-comel']\n",
    "word_vector_wiki.batch_n_closest(words, num_closest=8,\n",
    "                                 return_similarity=False,soft=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculate vb - va + vc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['kerajaan', 'penjara', 'pemerintah', 'sebat', 'jas']\n"
     ]
    }
   ],
   "source": [
    "print(word_vector_news.analogy('anwar', 'penjara', 'kerajaan', 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['kerajaan', 'penjara', 'pemerintah', 'hospital', 'kesultanan']\n"
     ]
    }
   ],
   "source": [
    "print(word_vector_wiki.analogy('anwar', 'penjara', 'kerajaan', 5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Word2vec calculator\n",
    "\n",
    "You can put any equation you wanted."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['mahathir',\n",
       " 'anwar',\n",
       " 'trump',\n",
       " 'duterte',\n",
       " 'netanyahu',\n",
       " 'jokowi',\n",
       " 'rusia',\n",
       " 'kj',\n",
       " 'obama']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word_vector_news.calculator('anwar + amerika + mahathir', num_closest=8, metric='cosine',\n",
    "                      return_similarity=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['mahathir',\n",
       " 'anwar',\n",
       " 'sukarno',\n",
       " 'suharto',\n",
       " 'hamas',\n",
       " 'sparta',\n",
       " 'amerika',\n",
       " 'iraq',\n",
       " 'lubnan']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word_vector_wiki.calculator('anwar + amerika + mahathir', num_closest=8, metric='cosine',\n",
    "                      return_similarity=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualize scatter-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19788 characters]\n",
      "text/plain": [
       "<Figure size 504x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "word = 'anwar'\n",
    "result = word_vector_news.n_closest(word=word, num_closest=8, metric='cosine')\n",
    "data = word_vector_news.scatter_plot(result, centre = word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27636 characters]\n",
      "text/plain": [
       "<Figure size 504x504 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "word = 'anwar'\n",
    "result = word_vector_wiki.n_closest(word=word, num_closest=8, metric='cosine')\n",
    "data = word_vector_wiki.scatter_plot(result, centre = word)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualize tree-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 504x504 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 73544 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "word = 'anwar'\n",
    "result = word_vector_news.n_closest(word=word, num_closest=8, metric='cosine')\n",
    "data = word_vector_news.tree_plot(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 504x504 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 70188 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "word = 'anwar'\n",
    "result = word_vector_wiki.n_closest(word=word, num_closest=8, metric='cosine')\n",
    "data = word_vector_wiki.tree_plot(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualize social-network\n",
    "\n",
    "```python\n",
    "\n",
    "def network(\n",
    "    self,\n",
    "    word,\n",
    "    num_closest = 8,\n",
    "    depth = 4,\n",
    "    min_distance = 0.5,\n",
    "    iteration = 300,\n",
    "    figsize = (15, 15),\n",
    "    node_color = '#72bbd0',\n",
    "    node_factor = 50,\n",
    "):\n",
    "\n",
    "    \"\"\"\n",
    "    plot a social network based on word given\n",
    "\n",
    "    Parameters\n",
    "    ----------\n",
    "    word : str\n",
    "        centre of social network.\n",
    "    num_closest: int, (default=8)\n",
    "        number of words closest to the node.\n",
    "    depth: int, (default=4)\n",
    "        depth of social network. More deeper more expensive to calculate, big^O(num_closest ** depth).\n",
    "    min_distance: float, (default=0.5)\n",
    "        minimum distance among nodes. Increase the value to increase the distance among nodes.\n",
    "    iteration: int, (default=300)\n",
    "        number of loops to train the social network to fit min_distace.\n",
    "    figsize: tuple, (default=(15, 15))\n",
    "        figure size for plot.\n",
    "    node_color: str, (default='#72bbd0')\n",
    "        color for nodes.\n",
    "    node_factor: int, (default=10)\n",
    "        size factor for depth nodes. Increase this value will increase nodes sizes based on depth.\n",
    "        \n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 89496 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "g = word_vector_news.network('mahathir', figsize = (10, 10), node_factor = 50, depth = 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 94728 characters]\n",
      "text/plain": [
       "<Figure size 720x720 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "g = word_vector_wiki.network('mahathir', figsize = (10, 10), node_factor = 50, depth = 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get embedding from a word"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(256,)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "word_vector_wiki.get_vector_by_name('najib').shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If a word not found in the vocabulary, it will throw an exception with top-5 nearest words"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "ename": "Exception",
     "evalue": "input not found in dictionary, here top-5 nearest words [husein, husei, husenil, husen, secomel]",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-26-0460b04adbfb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mword_vector_wiki\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_vector_by_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'husein-comel'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/Documents/Malaya/malaya/wordvector.py\u001b[0m in \u001b[0;36mget_vector_by_name\u001b[0;34m(self, word)\u001b[0m\n\u001b[1;32m    127\u001b[0m             raise Exception(\n\u001b[1;32m    128\u001b[0m                 \u001b[0;34m'input not found in dictionary, here top-5 nearest words [%s]'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 129\u001b[0;31m                 \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mstrings\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    130\u001b[0m             )\n\u001b[1;32m    131\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_embed_matrix\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_dictionary\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mword\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mException\u001b[0m: input not found in dictionary, here top-5 nearest words [husein, husei, husenil, husen, secomel]"
     ]
    }
   ],
   "source": [
    "word_vector_wiki.get_vector_by_name('husein-comel')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
