{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "80996"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import gensim\n",
    "\n",
    "f=open(\"Dataset_PW.txt\", \"r\")\n",
    "contents =f.read()\n",
    "\n",
    "dataset = []\n",
    "for sentence in gensim.summarization.textcleaner.get_sentences(contents):\n",
    "    sentences = list(gensim.utils.simple_preprocess (sentence))\n",
    "    dataset.append(sentences)\n",
    "len(dataset)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The 'Dataset.txt' file consists of API descriptions of over 15,000 APIs.\n",
    "\n",
    "Using the 'Dataset_PW.txt' file, a dataset which consists of sentences, is created."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(14745994, 20415810)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model_1 = gensim.models.Word2Vec (dataset, size=300, window=10, min_count=5, workers=10)\n",
    "model_1.train(dataset,total_examples=len(dataset),epochs=15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using gensim, a word2vec model is built and trained using the above dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_1.save(\"word2vec_model1.model\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The word2vec model is saved to the directory as a *.model* file."
   ]
  }
 ],
 "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.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
