{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'2.0.8'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import keras\n",
    "keras.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Using word embeddings\n",
    "\n",
    "This notebook contains the second code sample found in Chapter 6, Section 1 of [Deep Learning with Python](https://www.manning.com/books/deep-learning-with-python?a_aid=keras&a_bid=76564dff). Note that the original text features far more content, in particular further explanations and figures: in this notebook, you will only find source code and related comments.\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "Another popular and powerful way to associate a vector with a word is the use of dense \"word vectors\", also called \"word embeddings\". \n",
    "While the vectors obtained through one-hot encoding are binary, sparse (mostly made of zeros) and very high-dimensional (same dimensionality as the \n",
    "number of words in the vocabulary), \"word embeddings\" are low-dimensional floating point vectors \n",
    "(i.e. \"dense\" vectors, as opposed to sparse vectors). \n",
    "Unlike word vectors obtained via one-hot encoding, word embeddings are learned from data. \n",
    "It is common to see word embeddings that are 256-dimensional, 512-dimensional, or 1024-dimensional when dealing with very large vocabularies. \n",
    "On the other hand, one-hot encoding words generally leads to vectors that are 20,000-dimensional or higher (capturing a vocabulary of 20,000 \n",
    "token in this case). So, word embeddings pack more information into far fewer dimensions. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![word embeddings vs. one hot encoding](https://s3.amazonaws.com/book.keras.io/img/ch6/word_embeddings.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are two ways to obtain word embeddings:\n",
    "\n",
    "* Learn word embeddings jointly with the main task you care about (e.g. document classification or sentiment prediction). \n",
    "In this setup, you would start with random word vectors, then learn your word vectors in the same way that you learn the weights of a neural network.\n",
    "* Load into your model word embeddings that were pre-computed using a different machine learning task than the one you are trying to solve. \n",
    "These are called \"pre-trained word embeddings\". \n",
    "\n",
    "Let's take a look at both."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Learning word embeddings with the `Embedding` layer\n",
    "\n",
    "\n",
    "The simplest way to associate a dense vector to a word would be to pick the vector at random. The problem with this approach is that the \n",
    "resulting embedding space would have no structure: for instance, the words \"accurate\" and \"exact\" may end up with completely different \n",
    "embeddings, even though they are interchangeable in most sentences. It would be very difficult for a deep neural network to make sense of \n",
    "such a noisy, unstructured embedding space. \n",
    "\n",
    "To get a bit more abstract: the geometric relationships between word vectors should reflect the semantic relationships between these words. \n",
    "Word embeddings are meant to map human language into a geometric space. For instance, in a reasonable embedding space, we would expect \n",
    "synonyms to be embedded into similar word vectors, and in general we would expect the geometric distance (e.g. L2 distance) between any two \n",
    "word vectors to relate to the semantic distance of the associated words (words meaning very different things would be embedded to points \n",
    "far away from each other, while related words would be closer). Even beyond mere distance, we may want specific __directions__ in the \n",
    "embedding space to be meaningful. \n",
    "\n",
    "[...]\n",
    "\n",
    "\n",
    "In real-world word embedding spaces, common examples of meaningful geometric transformations are \"gender vectors\" and \"plural vector\". For \n",
    "instance, by adding a \"female vector\" to the vector \"king\", one obtain the vector \"queen\". By adding a \"plural vector\", one obtain \"kings\". \n",
    "Word embedding spaces typically feature thousands of such interpretable and potentially useful vectors.\n",
    "\n",
    "Is there some \"ideal\" word embedding space that would perfectly map human language and could be used for any natural language processing \n",
    "task? Possibly, but in any case, we have yet to compute anything of the sort. Also, there isn't such a thing as \"human language\", there are \n",
    "many different languages and they are not isomorphic, as a language is the reflection of a specific culture and a specific context. But more \n",
    "pragmatically, what makes a good word embedding space depends heavily on your task: the perfect word embedding space for an \n",
    "English-language movie review sentiment analysis model may look very different from the perfect embedding space for an English-language \n",
    "legal document classification model, because the importance of certain semantic relationships varies from task to task.\n",
    "\n",
    "It is thus reasonable to __learn__ a new embedding space with every new task. Thankfully, backpropagation makes this really easy, and Keras makes it \n",
    "even easier. It's just about learning the weights of a layer: the `Embedding` layer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from keras.layers import Embedding\n",
    "\n",
    "# The Embedding layer takes at least two arguments:\n",
    "# the number of possible tokens, here 1000 (1 + maximum word index),\n",
    "# and the dimensionality of the embeddings, here 64.\n",
    "embedding_layer = Embedding(1000, 64)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "The `Embedding` layer is best understood as a dictionary mapping integer indices (which stand for specific words) to dense vectors. It takes \n",
    "as input integers, it looks up these integers into an internal dictionary, and it returns the associated vectors. It's effectively a dictionary lookup."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "The `Embedding` layer takes as input a 2D tensor of integers, of shape `(samples, sequence_length)`, where each entry is a sequence of \n",
    "integers. It can embed sequences of variable lengths, so for instance we could feed into our embedding layer above batches that could have \n",
    "shapes `(32, 10)` (batch of 32 sequences of length 10) or `(64, 15)` (batch of 64 sequences of length 15). All sequences in a batch must \n",
    "have the same length, though (since we need to pack them into a single tensor), so sequences that are shorter than others should be padded \n",
    "with zeros, and sequences that are longer should be truncated.\n",
    "\n",
    "This layer returns a 3D floating point tensor, of shape `(samples, sequence_length, embedding_dimensionality)`. Such a 3D tensor can then \n",
    "be processed by a RNN layer or a 1D convolution layer (both will be introduced in the next sections).\n",
    "\n",
    "When you instantiate an `Embedding` layer, its weights (its internal dictionary of token vectors) are initially random, just like with any \n",
    "other layer. During training, these word vectors will be gradually adjusted via backpropagation, structuring the space into something that the \n",
    "downstream model can exploit. Once fully trained, your embedding space will show a lot of structure -- a kind of structure specialized for \n",
    "the specific problem you were training your model for.\n",
    "\n",
    "Let's apply this idea to the IMDB movie review sentiment prediction task that you are already familiar with. Let's quickly prepare \n",
    "the data. We will restrict the movie reviews to the top 10,000 most common words (like we did the first time we worked with this dataset), \n",
    "and cut the reviews after only 20 words. Our network will simply learn 8-dimensional embeddings for each of the 10,000 words, turn the \n",
    "input integer sequences (2D integer tensor) into embedded sequences (3D float tensor), flatten the tensor to 2D, and train a single `Dense` \n",
    "layer on top for classification."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading data from https://s3.amazonaws.com/text-datasets/imdb.npz\n",
      "12460032/17464789 [====================>.........] - ETA: 0s"
     ]
    }
   ],
   "source": [
    "from keras.datasets import imdb\n",
    "from keras import preprocessing\n",
    "\n",
    "# Number of words to consider as features\n",
    "max_features = 10000\n",
    "# Cut texts after this number of words \n",
    "# (among top max_features most common words)\n",
    "maxlen = 20\n",
    "\n",
    "# Load the data as lists of integers.\n",
    "(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)\n",
    "\n",
    "# This turns our lists of integers\n",
    "# into a 2D integer tensor of shape `(samples, maxlen)`\n",
    "x_train = preprocessing.sequence.pad_sequences(x_train, maxlen=maxlen)\n",
    "x_test = preprocessing.sequence.pad_sequences(x_test, maxlen=maxlen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_2 (Embedding)      (None, 20, 8)             80000     \n",
      "_________________________________________________________________\n",
      "flatten_1 (Flatten)          (None, 160)               0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 1)                 161       \n",
      "=================================================================\n",
      "Total params: 80,161\n",
      "Trainable params: 80,161\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 20000 samples, validate on 5000 samples\n",
      "Epoch 1/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.6560 - acc: 0.6482 - val_loss: 0.5906 - val_acc: 0.7146\n",
      "Epoch 2/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.5189 - acc: 0.7595 - val_loss: 0.5117 - val_acc: 0.7364\n",
      "Epoch 3/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.4512 - acc: 0.7933 - val_loss: 0.4949 - val_acc: 0.7470\n",
      "Epoch 4/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.4190 - acc: 0.8069 - val_loss: 0.4905 - val_acc: 0.7538\n",
      "Epoch 5/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.3965 - acc: 0.8198 - val_loss: 0.4914 - val_acc: 0.7572\n",
      "Epoch 6/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.3784 - acc: 0.8311 - val_loss: 0.4953 - val_acc: 0.7594\n",
      "Epoch 7/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.3624 - acc: 0.8419 - val_loss: 0.5004 - val_acc: 0.7574\n",
      "Epoch 8/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.3474 - acc: 0.8484 - val_loss: 0.5058 - val_acc: 0.7572\n",
      "Epoch 9/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.3330 - acc: 0.8582 - val_loss: 0.5122 - val_acc: 0.7528\n",
      "Epoch 10/10\n",
      "20000/20000 [==============================] - 2s - loss: 0.3194 - acc: 0.8669 - val_loss: 0.5183 - val_acc: 0.7554\n"
     ]
    }
   ],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers import Flatten, Dense\n",
    "\n",
    "model = Sequential()\n",
    "# We specify the maximum input length to our Embedding layer\n",
    "# so we can later flatten the embedded inputs\n",
    "model.add(Embedding(10000, 8, input_length=maxlen))\n",
    "# After the Embedding layer, \n",
    "# our activations have shape `(samples, maxlen, 8)`.\n",
    "\n",
    "# We flatten the 3D tensor of embeddings \n",
    "# into a 2D tensor of shape `(samples, maxlen * 8)`\n",
    "model.add(Flatten())\n",
    "\n",
    "# We add the classifier on top\n",
    "model.add(Dense(1, activation='sigmoid'))\n",
    "model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])\n",
    "model.summary()\n",
    "\n",
    "history = model.fit(x_train, y_train,\n",
    "                    epochs=10,\n",
    "                    batch_size=32,\n",
    "                    validation_split=0.2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We get to a validation accuracy of ~76%, which is pretty good considering that we only look at the first 20 words in every review. But \n",
    "note that merely flattening the embedded sequences and training a single `Dense` layer on top leads to a model that treats each word in the \n",
    "input sequence separately, without considering inter-word relationships and structure sentence (e.g. it would likely treat both _\"this movie \n",
    "is shit\"_ and _\"this movie is the shit\"_ as being negative \"reviews\"). It would be much better to add recurrent layers or 1D convolutional \n",
    "layers on top of the embedded sequences to learn features that take into account each sequence as a whole. That's what we will focus on in \n",
    "the next few sections."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using pre-trained word embeddings\n",
    "\n",
    "\n",
    "Sometimes, you have so little training data available that could never use your data alone to learn an appropriate task-specific embedding \n",
    "of your vocabulary. What to do then?\n",
    "\n",
    "Instead of learning word embeddings jointly with the problem you want to solve, you could be loading embedding vectors from a pre-computed \n",
    "embedding space known to be highly structured and to exhibit useful properties -- that captures generic aspects of language structure. The \n",
    "rationale behind using pre-trained word embeddings in natural language processing is very much the same as for using pre-trained convnets \n",
    "in image classification: we don't have enough data available to learn truly powerful features on our own, but we expect the features that \n",
    "we need to be fairly generic, i.e. common visual features or semantic features. In this case it makes sense to reuse features learned on a \n",
    "different problem.\n",
    "\n",
    "Such word embeddings are generally computed using word occurrence statistics (observations about what words co-occur in sentences or \n",
    "documents), using a variety of techniques, some involving neural networks, others not. The idea of a dense, low-dimensional embedding space \n",
    "for words, computed in an unsupervised way, was initially explored by Bengio et al. in the early 2000s, but it only started really taking \n",
    "off in research and industry applications after the release of one of the most famous and successful word embedding scheme: the Word2Vec \n",
    "algorithm, developed by Mikolov at Google in 2013. Word2Vec dimensions capture specific semantic properties, e.g. gender.\n",
    "\n",
    "There are various pre-computed databases of word embeddings that can download and start using in a Keras `Embedding` layer. Word2Vec is one \n",
    "of them. Another popular one is called \"GloVe\", developed by Stanford researchers in 2014. It stands for \"Global Vectors for Word \n",
    "Representation\", and it is an embedding technique based on factorizing a matrix of word co-occurrence statistics. Its developers have made \n",
    "available pre-computed embeddings for millions of English tokens, obtained from Wikipedia data or from Common Crawl data.\n",
    "\n",
    "Let's take a look at how you can get started using GloVe embeddings in a Keras model. The same method will of course be valid for Word2Vec \n",
    "embeddings or any other word embedding database that you can download. We will also use this example to refresh the text tokenization \n",
    "techniques we introduced a few paragraphs ago: we will start from raw text, and work our way up."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Putting it all together: from raw text to word embeddings\n",
    "\n",
    "\n",
    "We will be using a model similar to the one we just went over -- embedding sentences in sequences of vectors, flattening them and training a \n",
    "`Dense` layer on top. But we will do it using pre-trained word embeddings, and instead of using the pre-tokenized IMDB data packaged in \n",
    "Keras, we will start from scratch, by downloading the original text data."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Download the IMDB data as raw text\n",
    "\n",
    "\n",
    "First, head to `http://ai.stanford.edu/~amaas/data/sentiment/` and download the raw IMDB dataset (if the URL isn't working anymore, just \n",
    "Google \"IMDB dataset\"). Uncompress it.\n",
    "\n",
    "Now let's collect the individual training reviews into a list of strings, one string per review, and let's also collect the review labels \n",
    "(positive / negative) into a `labels` list:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "imdb_dir = '/home/ubuntu/data/aclImdb'\n",
    "train_dir = os.path.join(imdb_dir, 'train')\n",
    "\n",
    "labels = []\n",
    "texts = []\n",
    "\n",
    "for label_type in ['neg', 'pos']:\n",
    "    dir_name = os.path.join(train_dir, label_type)\n",
    "    for fname in os.listdir(dir_name):\n",
    "        if fname[-4:] == '.txt':\n",
    "            f = open(os.path.join(dir_name, fname))\n",
    "            texts.append(f.read())\n",
    "            f.close()\n",
    "            if label_type == 'neg':\n",
    "                labels.append(0)\n",
    "            else:\n",
    "                labels.append(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Tokenize the data\n",
    "\n",
    "\n",
    "Let's vectorize the texts we collected, and prepare a training and validation split.\n",
    "We will merely be using the concepts we introduced earlier in this section.\n",
    "\n",
    "Because pre-trained word embeddings are meant to be particularly useful on problems where little training data is available (otherwise, \n",
    "task-specific embeddings are likely to outperform them), we will add the following twist: we restrict the training data to its first 200 \n",
    "samples. So we will be learning to classify movie reviews after looking at just 200 examples...\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 88582 unique tokens.\n",
      "Shape of data tensor: (25000, 100)\n",
      "Shape of label tensor: (25000,)\n"
     ]
    }
   ],
   "source": [
    "from keras.preprocessing.text import Tokenizer\n",
    "from keras.preprocessing.sequence import pad_sequences\n",
    "import numpy as np\n",
    "\n",
    "maxlen = 100  # We will cut reviews after 100 words\n",
    "training_samples = 200  # We will be training on 200 samples\n",
    "validation_samples = 10000  # We will be validating on 10000 samples\n",
    "max_words = 10000  # We will only consider the top 10,000 words in the dataset\n",
    "\n",
    "tokenizer = Tokenizer(num_words=max_words)\n",
    "tokenizer.fit_on_texts(texts)\n",
    "sequences = tokenizer.texts_to_sequences(texts)\n",
    "\n",
    "word_index = tokenizer.word_index\n",
    "print('Found %s unique tokens.' % len(word_index))\n",
    "\n",
    "data = pad_sequences(sequences, maxlen=maxlen)\n",
    "\n",
    "labels = np.asarray(labels)\n",
    "print('Shape of data tensor:', data.shape)\n",
    "print('Shape of label tensor:', labels.shape)\n",
    "\n",
    "# Split the data into a training set and a validation set\n",
    "# But first, shuffle the data, since we started from data\n",
    "# where sample are ordered (all negative first, then all positive).\n",
    "indices = np.arange(data.shape[0])\n",
    "np.random.shuffle(indices)\n",
    "data = data[indices]\n",
    "labels = labels[indices]\n",
    "\n",
    "x_train = data[:training_samples]\n",
    "y_train = labels[:training_samples]\n",
    "x_val = data[training_samples: training_samples + validation_samples]\n",
    "y_val = labels[training_samples: training_samples + validation_samples]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Download the GloVe word embeddings\n",
    "\n",
    "\n",
    "Head to `https://nlp.stanford.edu/projects/glove/` (where you can learn more about the GloVe algorithm), and download the pre-computed \n",
    "embeddings from 2014 English Wikipedia. It's a 822MB zip file named `glove.6B.zip`, containing 100-dimensional embedding vectors for \n",
    "400,000 words (or non-word tokens). Un-zip it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pre-process the embeddings\n",
    "\n",
    "\n",
    "Let's parse the un-zipped file (it's a `txt` file) to build an index mapping words (as strings) to their vector representation (as number \n",
    "vectors)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Found 400000 word vectors.\n"
     ]
    }
   ],
   "source": [
    "glove_dir = '/home/ubuntu/data/'\n",
    "\n",
    "embeddings_index = {}\n",
    "f = open(os.path.join(glove_dir, 'glove.6B.100d.txt'))\n",
    "for line in f:\n",
    "    values = line.split()\n",
    "    word = values[0]\n",
    "    coefs = np.asarray(values[1:], dtype='float32')\n",
    "    embeddings_index[word] = coefs\n",
    "f.close()\n",
    "\n",
    "print('Found %s word vectors.' % len(embeddings_index))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Now let's build an embedding matrix that we will be able to load into an `Embedding` layer. It must be a matrix of shape `(max_words, \n",
    "embedding_dim)`, where each entry `i` contains the `embedding_dim`-dimensional vector for the word of index `i` in our reference word index \n",
    "(built during tokenization). Note that the index `0` is not supposed to stand for any word or token -- it's a placeholder."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "embedding_dim = 100\n",
    "\n",
    "embedding_matrix = np.zeros((max_words, embedding_dim))\n",
    "for word, i in word_index.items():\n",
    "    embedding_vector = embeddings_index.get(word)\n",
    "    if i < max_words:\n",
    "        if embedding_vector is not None:\n",
    "            # Words not found in embedding index will be all-zeros.\n",
    "            embedding_matrix[i] = embedding_vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Define a model\n",
    "\n",
    "We will be using the same model architecture as before:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_4 (Embedding)      (None, 100, 100)          1000000   \n",
      "_________________________________________________________________\n",
      "flatten_3 (Flatten)          (None, 10000)             0         \n",
      "_________________________________________________________________\n",
      "dense_4 (Dense)              (None, 32)                320032    \n",
      "_________________________________________________________________\n",
      "dense_5 (Dense)              (None, 1)                 33        \n",
      "=================================================================\n",
      "Total params: 1,320,065\n",
      "Trainable params: 1,320,065\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers import Embedding, Flatten, Dense\n",
    "\n",
    "model = Sequential()\n",
    "model.add(Embedding(max_words, embedding_dim, input_length=maxlen))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(32, activation='relu'))\n",
    "model.add(Dense(1, activation='sigmoid'))\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load the GloVe embeddings in the model\n",
    "\n",
    "\n",
    "The `Embedding` layer has a single weight matrix: a 2D float matrix where each entry `i` is the word vector meant to be associated with \n",
    "index `i`. Simple enough. Let's just load the GloVe matrix we prepared into our `Embedding` layer, the first layer in our model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "model.layers[0].set_weights([embedding_matrix])\n",
    "model.layers[0].trainable = False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Additionally, we freeze the embedding layer (we set its `trainable` attribute to `False`), following the same rationale as what you are \n",
    "already familiar with in the context of pre-trained convnet features: when parts of a model are pre-trained (like our `Embedding` layer), \n",
    "and parts are randomly initialized (like our classifier), the pre-trained parts should not be updated during training to avoid forgetting \n",
    "what they already know. The large gradient update triggered by the randomly initialized layers would be very disruptive to the already \n",
    "learned features."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Train and evaluate\n",
    "\n",
    "Let's compile our model and train it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 200 samples, validate on 10000 samples\n",
      "Epoch 1/10\n",
      "200/200 [==============================] - 1s - loss: 1.9075 - acc: 0.5050 - val_loss: 0.7027 - val_acc: 0.5102\n",
      "Epoch 2/10\n",
      "200/200 [==============================] - 0s - loss: 0.7329 - acc: 0.7100 - val_loss: 0.8200 - val_acc: 0.5000\n",
      "Epoch 3/10\n",
      "200/200 [==============================] - 0s - loss: 0.4876 - acc: 0.7400 - val_loss: 0.6917 - val_acc: 0.5616\n",
      "Epoch 4/10\n",
      "200/200 [==============================] - 0s - loss: 0.3640 - acc: 0.8400 - val_loss: 0.7005 - val_acc: 0.5557\n",
      "Epoch 5/10\n",
      "200/200 [==============================] - 0s - loss: 0.2673 - acc: 0.8950 - val_loss: 1.2560 - val_acc: 0.4999\n",
      "Epoch 6/10\n",
      "200/200 [==============================] - 0s - loss: 0.1936 - acc: 0.9400 - val_loss: 0.7294 - val_acc: 0.5704\n",
      "Epoch 7/10\n",
      "200/200 [==============================] - 0s - loss: 0.2455 - acc: 0.8800 - val_loss: 0.7187 - val_acc: 0.5659\n",
      "Epoch 8/10\n",
      "200/200 [==============================] - 0s - loss: 0.0591 - acc: 0.9950 - val_loss: 0.7393 - val_acc: 0.5723\n",
      "Epoch 9/10\n",
      "200/200 [==============================] - 0s - loss: 0.0399 - acc: 1.0000 - val_loss: 0.8691 - val_acc: 0.5522\n",
      "Epoch 10/10\n",
      "200/200 [==============================] - 0s - loss: 0.0283 - acc: 1.0000 - val_loss: 0.9322 - val_acc: 0.5413\n"
     ]
    }
   ],
   "source": [
    "model.compile(optimizer='rmsprop',\n",
    "              loss='binary_crossentropy',\n",
    "              metrics=['acc'])\n",
    "history = model.fit(x_train, y_train,\n",
    "                    epochs=10,\n",
    "                    batch_size=32,\n",
    "                    validation_data=(x_val, y_val))\n",
    "model.save_weights('pre_trained_glove_model.h5')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's plot its performance over time:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEICAYAAACktLTqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt8VNW5//HPAwS537EqCKHWKtdAiKACKsULWoGq1ILY\nI1pBUbTV9lgrtHps0V+rVatSK3psa0UoxwtSRe1RaZVaFFABgSOgIAYQAbkIQSDy/P5YkzAJuUzC\nhJnZ+b5fr3nNzN5r9n5mT/LMmrXXXsvcHRERiZY6qQ5ARESST8ldRCSClNxFRCJIyV1EJIKU3EVE\nIkjJXUQkgpTcI8zM6prZTjPrkMyyqWRm3zCzpPffNbMzzWxN3PMPzGxAImWrsa9HzeyW6r5eJBH1\nUh2AHGBmO+OeNgL2AF/Fnl/l7lOrsj13/wpokuyytYG7n5CM7ZjZlcCl7n5G3LavTMa2RSqi5J5G\n3L04ucZqhle6+yvllTezeu5eeDhiE6mM/h7Ti5plMoiZ/crM/mpm08zsC+BSMzvFzOaZ2TYz22B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V2oCaZUREIknJXUQkgpTcRUQiKK0uYtq3bx/5+fl8+eWXqQ5FKtCgQQPa\nt29PVlZ5w6WISKqlVXLPz8+nadOmZGdnEwYalHTj7mzZsoX8/Hw6depU+QtEJCUqbZYxs8fM7DMz\ne7+c9RabZmuVmS02s9zqBvPll1/SunVrJfY0Zma0bt1av64ko0ydCtnZUKdOuJ9apanmMzOORNrc\n/0QF81YSZrs5PnYbSxjFr9qU2NOfPiPJJFOnwtix8PHH4B7ux449/An+cMdRaXJ399cJQ6SWZxjw\nuAfzgBYWm+BXRGq3dKgxT5gABQUllxUUhOVRjiMZvWXaUXKqrXzKmZXHzMbGZlZfsGnTpiTsOrm2\nbNlCz5496dmzJ0cddRTt2rUrfr53796EtnH55ZfzwQcfVFhm8uTJTE3V70KRwyRdasxryxmGrLzl\nkYkjkYlWCbOuv1/OuueB/nHPXyU223xFt969e3tpy5YtO2hZRZ54wr1jR3ezcP/EE1V6eYVuvfVW\nv+uuuw5avn//fv/qq6+St6MMVdXPSmqfjh3dQ1oveevYUXEcShzAAj9ME2Svo+T8ku2p3vyPVXI4\nawWrVq2iS5cujBo1iq5du7JhwwbGjh1LXl4eXbt25fbbby8u279/f9577z0KCwtp0aIFN998Mzk5\nOZxyyil89tlnAEycOJH77ruvuPzNN99Mnz59OOGEE3jzzTABza5du7jooovo0qULw4cPJy8vj/fe\ne++g2G699VZOOukkunXrxtVXX130BcuKFSv41re+RU5ODrm5uaxZswaAO+64g+7du5OTk8OEw/27\nVGqVdKkxT5oEjRqVXNaoUVge6TgS+Qag4pr7twlTjxlwMvB2Its81Jp7TX8bx9fcV65c6Wbm8+fP\nL16/ZcsWd3fft2+f9+/f35cuXeru7v369fN3333X9+3b54DPnj3b3d1vuOEGv/POO93dfcKECX7v\nvfcWl7/pppvc3f25557zc845x93d77zzTr/mmmvc3f29997zOnXq+LvvvntQnEVx7N+/30eMGFG8\nv9zcXJ81a5a7u+/evdt37drls2bN8v79+3tBQUGJ11aHau5SmXSpMbvX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4rBSpR/wfWCJmb0XW3aLu89OYUySXq4DpsYqQh8B\nl6c4npRw97fM7CngHUIvs3epBcMQaPgBEZEIyrRmGRERSYCSu4hIBCm5i4hEkJK7iEgEKbmLiESQ\nkruISAQpuYuIRND/B8sHA/B6JcgEAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff6bd49d748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEICAYAAABYoZ8gAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmUVNW1x/HvZpZBZgdAAYcnNMhkBzRIEDUEo8JDiQEB\n0WhQFI0a84JoosGQoDGOMUZicAIlPhWDIxoljxgVaQhCBAmogA1EAQGZRJre749zG6qhh+ru6r5F\n1++zVq2quuOu6q59zz333HPM3RERkcxRI+4ARESkainxi4hkGCV+EZEMo8QvIpJhlPhFRDKMEr+I\nSIZR4pcyM7OaZrbNzI5O5bJxMrPjzCzlbZvN7EwzW5nwfpmZ9Ulm2XLs62EzG1/e9UvY7i/N7NFU\nb1fiUyvuAKTymdm2hLf1gV3Anuj95e4+rSzbc/c9QMNUL5sJ3P2EVGzHzC4DRrj7aQnbviwV25bq\nT4k/A7j73sQblSgvc/e/Fre8mdVy97yqiE1Eqp6qeqTgVP7PZvaUmW0FRpjZKWb2rpltNrN1Znaf\nmdWOlq9lZm5m7aL3U6P5r5jZVjN7x8zal3XZaP5ZZvZvM9tiZveb2T/M7OJi4k4mxsvNbIWZbTKz\n+xLWrWlmd5vZRjP7GBhQwvdzk5lN32/aA2Z2V/T6MjNbGn2ej6LSeHHbyjWz06LX9c3siSi2D4CT\n9lv2ZjP7ONruB2Y2MJp+IvA7oE9UjbYh4bu9NWH9K6LPvtHMnjezI5P5bkpjZoOjeDab2ZtmdkLC\nvPFmttbMvjSzDxM+68lmtiCa/pmZ/SbZ/U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XlFbnt\nunXrlrpMeTVv3pxFixbRp08fHnjgAS6//HIAZs2axRVXXMG8efPo2bMne/bsSel+k6XELyJlEtc1\ntS+//JJGjRpx6KGHsm7dOmbNSn1/j7179+bpp58GYPHixUWeUSTq1asXs2fPZuPGjeTl5TF9+nT6\n9u3L+vXrcXe+973vMWHCBBYsWMCePXvIzc3l9NNP54477mDDhg3s2L/OrIpUizp+Eak6cV1T69Gj\nB1lZWXTo0IG2bdvSu3fvlO/j6quv5qKLLiIrK2vvo6Capiht2rThtttu47TTTsPdOffcczn77LNZ\nsGABl156Ke6OmXH77beTl5fHhRdeyNatW8nPz+eGG26gUaNGKf8MySh1zN04ZGdnuwZiEak6S5cu\npWPHjnGHEbu8vDzy8vKoV68ey5cvp3///ixfvpxatdKrjFzU38vM5rt7djGrFJJen0ZEJEbbtm3j\njDPOIC8vD3fnoYceSruknwrV7xOJiJRTkyZNmD9/ftxhVDpd3BURyTBK/CIiGUaJX0Qkw5Rax29m\nU4BzgM/dvXMR838CFDTkqgV0BFpG4+2uBLYCe4C8ZK84i4hI5UmmxP8oMKC4me7+G3fv5u7dgBuB\n/9tvQPV+0XwlfREpUr9+/Q64Ieuee+5hzJgxJa7XsGFDANauXcuQIUOKXOa0006jtObh99xzT6Gb\nqb773e+mpC+dW2+9lTvvvLPC20m1UhO/u88Bvihtucgw4KkKRSQiGWfYsGFMnz690LTp06czbNiw\npNZv1aoVzzzzTLn3v3/if/nll2nSpEm5t5fuUlbHb2b1CWcGzyZMduA1M5tvZqNLWX+0meWYWc76\n9etTFZaIHASGDBnCSy+9tHfglZUrV7J27Vr69Omzt219jx49OPHEE/nLX/5ywPorV66kc+dQE71z\n506GDh1Kx44dGTx4MDt37ty73JgxY/Z263zLLbcAcN9997F27Vr69etHv379AGjXrh0bNmwA4K67\n7qJz58507tx5b7fOK1eupGPHjvzwhz+kU6dO9O/fv9B+irJw4UJOPvlkunTpwuDBg9m0adPe/Rd0\n1VzQQdz//d//7R2Mpnv37mzdurXc321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JMEr8IiIZRolfRCTD\n/D/w0XtHon6dFgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff68fa53320>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "acc = history.history['acc']\n",
    "val_acc = history.history['val_acc']\n",
    "loss = history.history['loss']\n",
    "val_loss = history.history['val_loss']\n",
    "\n",
    "epochs = range(1, len(acc) + 1)\n",
    "\n",
    "plt.plot(epochs, acc, 'bo', label='Training acc')\n",
    "plt.plot(epochs, val_acc, 'b', label='Validation acc')\n",
    "plt.title('Training and validation accuracy')\n",
    "plt.legend()\n",
    "\n",
    "plt.figure()\n",
    "\n",
    "plt.plot(epochs, loss, 'bo', label='Training loss')\n",
    "plt.plot(epochs, val_loss, 'b', label='Validation loss')\n",
    "plt.title('Training and validation loss')\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "The model quickly starts overfitting, unsurprisingly given the small number of training samples. Validation accuracy has high variance for \n",
    "the same reason, but seems to reach high 50s.\n",
    "\n",
    "Note that your mileage may vary: since we have so few training samples, performance is heavily dependent on which exact 200 samples we \n",
    "picked, and we picked them at random. If it worked really poorly for you, try picking a different random set of 200 samples, just for the \n",
    "sake of the exercise (in real life you don't get to pick your training data).\n",
    "\n",
    "We can also try to train the same model without loading the pre-trained word embeddings and without freezing the embedding layer. In that \n",
    "case, we would be learning a task-specific embedding of our input tokens, which is generally more powerful than pre-trained word embeddings \n",
    "when lots of data is available. However, in our case, we have only 200 training samples. Let's try it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "embedding_5 (Embedding)      (None, 100, 100)          1000000   \n",
      "_________________________________________________________________\n",
      "flatten_4 (Flatten)          (None, 10000)             0         \n",
      "_________________________________________________________________\n",
      "dense_6 (Dense)              (None, 32)                320032    \n",
      "_________________________________________________________________\n",
      "dense_7 (Dense)              (None, 1)                 33        \n",
      "=================================================================\n",
      "Total params: 1,320,065\n",
      "Trainable params: 1,320,065\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Train on 200 samples, validate on 10000 samples\n",
      "Epoch 1/10\n",
      "200/200 [==============================] - 1s - loss: 0.6941 - acc: 0.4750 - val_loss: 0.6920 - val_acc: 0.5213\n",
      "Epoch 2/10\n",
      "200/200 [==============================] - 0s - loss: 0.5050 - acc: 0.9900 - val_loss: 0.6949 - val_acc: 0.5138\n",
      "Epoch 3/10\n",
      "200/200 [==============================] - 0s - loss: 0.2807 - acc: 1.0000 - val_loss: 0.7131 - val_acc: 0.5125\n",
      "Epoch 4/10\n",
      "200/200 [==============================] - 0s - loss: 0.1223 - acc: 1.0000 - val_loss: 0.6997 - val_acc: 0.5214\n",
      "Epoch 5/10\n",
      "200/200 [==============================] - 0s - loss: 0.0584 - acc: 1.0000 - val_loss: 0.7043 - val_acc: 0.5183\n",
      "Epoch 6/10\n",
      "200/200 [==============================] - 0s - loss: 0.0307 - acc: 1.0000 - val_loss: 0.7051 - val_acc: 0.5248\n",
      "Epoch 7/10\n",
      "200/200 [==============================] - 0s - loss: 0.0166 - acc: 1.0000 - val_loss: 0.7345 - val_acc: 0.5282\n",
      "Epoch 8/10\n",
      "200/200 [==============================] - 0s - loss: 0.0098 - acc: 1.0000 - val_loss: 0.7173 - val_acc: 0.5199\n",
      "Epoch 9/10\n",
      "200/200 [==============================] - 0s - loss: 0.0058 - acc: 1.0000 - val_loss: 0.7201 - val_acc: 0.5253\n",
      "Epoch 10/10\n",
      "200/200 [==============================] - 0s - loss: 0.0035 - acc: 1.0000 - val_loss: 0.7244 - val_acc: 0.5264\n"
     ]
    }
   ],
   "source": [
    "from keras.models import Sequential\n",
    "from keras.layers import Embedding, Flatten, Dense\n",
    "\n",
    "model = Sequential()\n",
    "model.add(Embedding(max_words, embedding_dim, input_length=maxlen))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(32, activation='relu'))\n",
    "model.add(Dense(1, activation='sigmoid'))\n",
    "model.summary()\n",
    "\n",
    "model.compile(optimizer='rmsprop',\n",
    "              loss='binary_crossentropy',\n",
    "              metrics=['acc'])\n",
    "history = model.fit(x_train, y_train,\n",
    "                    epochs=10,\n",
    "                    batch_size=32,\n",
    "                    validation_data=(x_val, y_val))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEICAYAAACktLTqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt4VPW97/H3lxAM4X4JgkQItVbugRBBD94oaNEqPCq1\nIO4W3Yp6xFqqZ28qtvJose5q3dqW7ZZ6tLUilKPVYuul1WLRWpWgggIqbAUNIIarCCgEv+ePtSZM\nhkkyCRMms/J5Pc88sy6/Wes7a5LPWvNbM2vM3RERkWhpkekCREQk/RTuIiIRpHAXEYkghbuISAQp\n3EVEIkjhLiISQQr3CDOzHDP7zMx6pbNtJpnZV80s7Z/fNbMxZrYubvxdMzs1lbYNWNf9ZnZjQx8v\nkoqWmS5ADjKzz+JG84EvgAPh+JXuPq8+y3P3A0DbdLdtDtz9hHQsx8wuBy5x9zPiln15OpYtUhuF\nexPi7lXhGh4ZXu7uz9XU3sxaunvlkahNpC76e2xa1C2TRczsJ2b2ezObb2a7gEvM7GQze8XMdpjZ\nJjP7hZnlhu1bmpmbWVE4/nA4/2kz22Vm/zSzPvVtG84/28zeM7OdZvZLM/uHmU2poe5UarzSzNaa\n2XYz+0XcY3PM7D/NbKuZvQ+MrWX7zDSzBQnT5pjZXeHw5Wa2Onw+/xMeVde0rHIzOyMczjez34W1\nrQSGJbS9ycze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XqVEpLSxkwYAC33HJLVdtTTjmFN998k8rKSjp27MiMGTMoLi7m5JNP5pNP\nPgHgpptu4u67765qP2PGDIYPH84JJ5zAyy+/DMDu3bu58MIL6d+/PxMmTKC0tLRqxxPv5ptv5sQT\nT2TgwIFcddVVxL6A/9577/H1r3+d4uJiSkpKWLduHQC33XYbgwYNori4mJkzZ6Z/Y6VA4S4iNZo5\nE/bsqT5tz55gemN45513mD59OqtWraJnz57cfvvtlJWVsXz5cv7617+yatWqQx6zc+dOTj/9dJYv\nX87JJ5/MAw88kHTZ7s5rr73GHXfcUbWj+OUvf0n37t1ZtWoVP/rRj3jjjTeSPva6665j6dKlvPXW\nW+zcuZNnnnkGgEmTJjF9+nSWL1/Oyy+/TLdu3XjyySd5+umnee2111i+fDnXX399mrZO/SjcRaRG\nH35Yv+mH67jjjqO0tLRqfP78+ZSUlFBSUsLq1auThnvr1q05++yzARg2bFjV0XOiCy644JA2L730\nEhMnTgSguLiYAQMGJH3s888/z/DhwykuLubvf/87K1euZPv27WzZsoXzzjsPCD6Xnp+fz3PPPcdl\nl11G69atAejcuXP9N0QaqM9dRGrUq1fQFZNsemNo06ZN1fCaNWu45557eO211+jYsSOXXHJJ0o8G\ntmrVqmo4JyeHysrKpMs+6qij6myTzJ49e5g2bRqvv/46PXv25KabbsqKL4DpyF1EajR7NuTnV5+W\nnx9Mb2yffvop7dq1o3379mzatIlnn3027esYOXIkCxcuBOCtt95K+s5g7969tGjRgq5du7Jr1y4e\ne+wxADp16kRBQQFPPvkkEHx/YM+ePZx55pk88MAD7N27F4Bt27alve5U6MhdRGoU+1RMOj8tk6qS\nkhL69+9P37596d27NyNHpv/Cs9deey3f+c536N+/f9WtQ4cO1dp06dKF7373u/Tv358ePXowYsTB\nXxmdN28eV155JTNnzqRVq1Y89thjnHvuuSxfvpzS0lJyc3M577zzuPXWW9Nee10sU5ddLy0t9bKy\nsoysW6Q5W716Nf369ct0GU1CZWUllZWV5OXlsWbNGs466yzWrFlDy5ZN47g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7gvBY43sz5m1orgpMiiDNeU\nEWZmBP2pq939rkzXk2nu/kN3L3T3IoK/i7+5e+SPzmri7h8DH5nZCeGk0cCqDJaUSR8CJ5lZfvh/\nM5pmcHI5q34g290rzWwa8CzBGe8H3H1lhsvKlJHAvwBvmdmb4bQb3f2pDNYkTcu1wLzwQOh94NIM\n15MR7v6qmT0KvE7wKbM3aAaXIdDlB0REIijbumVERCQFCncRkQhSuIuIRJDCXUQkghTuIiIRpHAX\nEYkghbuISAT9f9OWSH2mH2LTAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff68c18a048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEICAYAAACktLTqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X98FfWd7/HXJ/wwIJTwI1YlQBCpEAoiHrFeRMRqF6uC\nWuqCwVa3bqoPLLraXanYrlJ5VF2vWnq5ttRifxibsri2bKtle5UtWCsSEKOACGKQAGqkgkhgIfC5\nf8wknMST5ISc5JxM3s/H4zzOmZnvmfmcCbzPzHfmzJi7IyIi0ZKV7gJERCT1FO4iIhGkcBcRiSCF\nu4hIBCncRUQiSOEuIhJBCndJyMw6mdknZjYwlW3TycxON7OUn/trZhebWXnc8CYzG59M2+NY1uNm\ndtfxvr+R+d5nZj9P9XwlfTqnuwBJDTP7JG6wO/A/wJFw+JvuXtyc+bn7EaBHqtt2BO5+RirmY2Y3\nAjPc/cK4ed+YinlL9CncI8Lda8M13DK80d3/X0Ptzayzu1e3RW0i0vbULdNBhLvdvzGzX5vZPmCG\nmZ1nZi+b2R4z22Vm882sS9i+s5m5meWHw0+G058zs31m9lczG9zctuH0S83sLTPba2Y/MrO/mNn1\nDdSdTI3fNLMtZvaRmc2Pe28nM3vEzHab2VZgUiPrZ46ZldQbt8DMHg5f32hmG8PP83a4Vd3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6txd37yk59kXLBnkoEDg66YRONFOiKlRYbK\nyclhzZo16S6j3Zg3r+6P2kA3DZGOrd0eUBWJp5uGiNSlLXeJjHQdYBfJRNpyF0khnWsvmUJb7iIp\n0hoXsxM5XtpyjzNx4sRP/SDp0Ucf5eabb270fT169ABg586dTJ2a+P7gF154IfVP/azv0UcfrfNj\noi9/+cspue7LPffcw0MPPdTi+Ujj2vJidiJNUbjHmT59OiUlJXXGlZSUMH369KTef+qpp7JkyZLj\nXn79cH/22WfJyck57vlJ22rri9k1Rt1DkrHdMrfdBqm+B8Xo0RBeaTehqVOncvfdd3Po0CG6du1K\neXk5O3fuZPz48XzyySdMmTKFjz76iMOHD3PfffcxZcqUOu8vLy/n8ssv54033uDAgQPccMMNvPba\nawwbNowDBw7Utrv55ptZvXo1Bw4cYOrUqdx7773Mnz+fnTt3MnHiRPr168fy5cvJz8+ntLSUfv36\n8fDDD7No0SIAbrzxRm677TbKy8u59NJLOf/883nppZfo378/v/vd7+jWrVuDn3HdunXcdNNNVFVV\nMWTIEBYtWkTv3r2ZP38+P/7xj+ncuTMFBQWUlJTw5z//mVtvvRUIbqm3YsWKdv9L1taUKefaq3tI\nQFvudfTp04exY8fy3HPPAcFW+zXXXIOZkZ2dzTPPPMPatWtZvnw5d9xxB439uvexxx6je/fubNy4\nkXvvvbfOOevz5s2jtLSUsrIy/vznP1NWVsasWbM49dRTWb58OcuXL68zrzVr1vDEE0+watUqXn75\nZX7605/y6quvAsFFzGbOnMn69evJycnh6aefbvQzfu1rX+OBBx6grKyMkSNHcu+99wLBJYxfffVV\nysrK+PGPfwzAQw89xIIFC1i3bh0rV65s9EtD2v5idg3JpO4h7UGkT8ZuuTe2hd2aarpmpkyZQklJ\nCT/72c+A4Jrrd911FytWrCArK4sdO3bw/vvvc/LJJyecz4oVK5g1axYAo0aNYtSoUbXTFi9ezMKF\nC6murmbXrl1s2LChzvT6XnzxRa666qraK1NeffXVrFy5ksmTJzN48GBGjx4NNH5ZYQiuL79nzx4m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NJA3dzzXNZaXLOOA6\n4HUzWxeOu8vdn01jTZJZvgUUhxtCW4Eb0lxPWrj7KjNbAqwlOMvsVTrAZQh0+QERkQhqb90yIiKS\nBIW7iEgEKdxFRCJI4S4iEkEKdxGRCFK4i4hEkMJdRCSC/j8V/tiI4+5lRgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff687df5048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "acc = history.history['acc']\n",
    "val_acc = history.history['val_acc']\n",
    "loss = history.history['loss']\n",
    "val_loss = history.history['val_loss']\n",
    "\n",
    "epochs = range(1, len(acc) + 1)\n",
    "\n",
    "plt.plot(epochs, acc, 'bo', label='Training acc')\n",
    "plt.plot(epochs, val_acc, 'b', label='Validation acc')\n",
    "plt.title('Training and validation accuracy')\n",
    "plt.legend()\n",
    "\n",
    "plt.figure()\n",
    "\n",
    "plt.plot(epochs, loss, 'bo', label='Training loss')\n",
    "plt.plot(epochs, val_loss, 'b', label='Validation loss')\n",
    "plt.title('Training and validation loss')\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Validation accuracy stalls in the low 50s. So in our case, pre-trained word embeddings does outperform jointly learned embeddings. If you \n",
    "increase the number of training samples, this will quickly stop being the case -- try it as an exercise.\n",
    "\n",
    "Finally, let's evaluate the model on the test data. First, we will need to tokenize the test data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test_dir = os.path.join(imdb_dir, 'test')\n",
    "\n",
    "labels = []\n",
    "texts = []\n",
    "\n",
    "for label_type in ['neg', 'pos']:\n",
    "    dir_name = os.path.join(test_dir, label_type)\n",
    "    for fname in sorted(os.listdir(dir_name)):\n",
    "        if fname[-4:] == '.txt':\n",
    "            f = open(os.path.join(dir_name, fname))\n",
    "            texts.append(f.read())\n",
    "            f.close()\n",
    "            if label_type == 'neg':\n",
    "                labels.append(0)\n",
    "            else:\n",
    "                labels.append(1)\n",
    "\n",
    "sequences = tokenizer.texts_to_sequences(texts)\n",
    "x_test = pad_sequences(sequences, maxlen=maxlen)\n",
    "y_test = np.asarray(labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And let's load and evaluate the first model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24736/25000 [============================>.] - ETA: 0s"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0.93747248332977295, 0.53659999999999997]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.load_weights('pre_trained_glove_model.h5')\n",
    "model.evaluate(x_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We get an appalling test accuracy of 54%. Working with just a handful of training samples is hard!"
   ]
  }
 ],
 "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
