Skip-gram word2vec

In this notebook, I'll lead you through using TensorFlow to implement the word2vec algorithm using the skip-gram architecture. By implementing this, you'll learn about embedding words for use in natural language processing. This will come in handy when dealing with things like machine translation.

Readings

Here are the resources I used to build this notebook. I suggest reading these either beforehand or while you're working on this material.

Word embeddings

When you're dealing with words in text, you end up with tens of thousands of classes to predict, one for each word. Trying to one-hot encode these words is massively inefficient, you'll have one element set to 1 and the other 50,000 set to 0. The matrix multiplication going into the first hidden layer will have almost all of the resulting values be zero. This a huge waste of computation.

To solve this problem and greatly increase the efficiency of our networks, we use what are called embeddings. Embeddings are just a fully connected layer like you've seen before. We call this layer the embedding layer and the weights are embedding weights. We skip the multiplication into the embedding layer by instead directly grabbing the hidden layer values from the weight matrix. We can do this because the multiplication of a one-hot encoded vector with a matrix returns the row of the matrix corresponding the index of the "on" input unit.

Instead of doing the matrix multiplication, we use the weight matrix as a lookup table. We encode the words as integers, for example "heart" is encoded as 958, "mind" as 18094. Then to get hidden layer values for "heart", you just take the 958th row of the embedding matrix. This process is called an embedding lookup and the number of hidden units is the embedding dimension.

There is nothing magical going on here. The embedding lookup table is just a weight matrix. The embedding layer is just a hidden layer. The lookup is just a shortcut for the matrix multiplication. The lookup table is trained just like any weight matrix as well.

Embeddings aren't only used for words of course. You can use them for any model where you have a massive number of classes. A particular type of model called Word2Vec uses the embedding layer to find vector representations of words that contain semantic meaning.

Word2Vec

The word2vec algorithm finds much more efficient representations by finding vectors that represent the words. These vectors also contain semantic information about the words. Words that show up in similar contexts, such as "black", "white", and "red" will have vectors near each other. There are two architectures for implementing word2vec, CBOW (Continuous Bag-Of-Words) and Skip-gram.

In this implementation, we'll be using the skip-gram architecture because it performs better than CBOW. Here, we pass in a word and try to predict the words surrounding it in the text. In this way, we can train the network to learn representations for words that show up in similar contexts.

First up, importing packages.


In [1]:
import time

import numpy as np
import tensorflow as tf

import utils

Load the text8 dataset, a file of cleaned up Wikipedia articles from Matt Mahoney. The next cell will download the data set to the data folder. Then you can extract it and delete the archive file to save storage space.


In [2]:
from urllib.request import urlretrieve
from os.path import isfile, isdir
from tqdm import tqdm
import zipfile

dataset_folder_path = 'data'
dataset_filename = 'text8.zip'
dataset_name = 'Text8 Dataset'

class DLProgress(tqdm):
    last_block = 0

    def hook(self, block_num=1, block_size=1, total_size=None):
        self.total = total_size
        self.update((block_num - self.last_block) * block_size)
        self.last_block = block_num

if not isfile(dataset_filename):
    with DLProgress(unit='B', unit_scale=True, miniters=1, desc=dataset_name) as pbar:
        urlretrieve(
            'http://mattmahoney.net/dc/text8.zip',
            dataset_filename,
            pbar.hook)

if not isdir(dataset_folder_path):
    with zipfile.ZipFile(dataset_filename) as zip_ref:
        zip_ref.extractall(dataset_folder_path)
        
with open('data/text8') as f:
    text = f.read()


Text8 Dataset: 31.4MB [00:16, 1.88MB/s]                            

Preprocessing

Here I'm fixing up the text to make training easier. This comes from the utils module I wrote. The preprocess function coverts any punctuation into tokens, so a period is changed to <PERIOD>. In this data set, there aren't any periods, but it will help in other NLP problems. I'm also removing all words that show up five or fewer times in the dataset. This will greatly reduce issues due to noise in the data and improve the quality of the vector representations. If you want to write your own functions for this stuff, go for it.


In [57]:
words = utils.preprocess(text)
print(words[:30])


['anarchism', 'originated', 'as', 'a', 'term', 'of', 'abuse', 'first', 'used', 'against', 'early', 'working', 'class', 'radicals', 'including', 'the', 'diggers', 'of', 'the', 'english', 'revolution', 'and', 'the', 'sans', 'culottes', 'of', 'the', 'french', 'revolution', 'whilst']

In [58]:
print("Total words: {}".format(len(words)))
print("Unique words: {}".format(len(set(words))))


Total words: 16680599
Unique words: 63641

And here I'm creating dictionaries to covert words to integers and backwards, integers to words. The integers are assigned in descending frequency order, so the most frequent word ("the") is given the integer 0 and the next most frequent is 1 and so on. The words are converted to integers and stored in the list int_words.


In [5]:
vocab_to_int, int_to_vocab = utils.create_lookup_tables(words)
int_words = [vocab_to_int[word] for word in words]

Subsampling

Words that show up often such as "the", "of", and "for" don't provide much context to the nearby words. If we discard some of them, we can remove some of the noise from our data and in return get faster training and better representations. This process is called subsampling by Mikolov. For each word $w_i$ in the training set, we'll discard it with probability given by

$$ P(w_i) = 1 - \sqrt{\frac{t}{f(w_i)}} $$

where $t$ is a threshold parameter and $f(w_i)$ is the frequency of word $w_i$ in the total dataset.

I'm going to leave this up to you as an exercise. Check out my solution to see how I did it.

Exercise: Implement subsampling for the words in int_words. That is, go through int_words and discard each word given the probablility $P(w_i)$ shown above. Note that $P(w_i)$ is that probability that a word is discarded. Assign the subsampled data to train_words.


In [6]:
from collections import Counter
import random

threshold = 1e-5
word_counts = Counter(int_words)
total_count = len(int_words)
freqs = {word: count/total_count for word, count in word_counts.items()}
p_drop = {word: 1 - np.sqrt(threshold/freqs[word]) for word in word_counts}
train_words = [word for word in int_words if random.random() < (1 - p_drop[word])]

Making batches

Now that our data is in good shape, we need to get it into the proper form to pass it into our network. With the skip-gram architecture, for each word in the text, we want to grab all the words in a window around that word, with size $C$.

From Mikolov et al.:

"Since the more distant words are usually less related to the current word than those close to it, we give less weight to the distant words by sampling less from those words in our training examples... If we choose $C = 5$, for each training word we will select randomly a number $R$ in range $< 1; C >$, and then use $R$ words from history and $R$ words from the future of the current word as correct labels."

Exercise: Implement a function get_target that receives a list of words, an index, and a window size, then returns a list of words in the window around the index. Make sure to use the algorithm described above, where you chose a random number of words to from the window.


In [7]:
def get_target(words, idx, window_size=5):
    ''' Get a list of words in a window around an index. '''
    
    R = np.random.randint(1, window_size+1)
    start = idx - R if (idx - R) > 0 else 0
    stop = idx + R
    target_words = set(words[start:idx] + words[idx+1:stop+1])
    
    return list(target_words)

Here's a function that returns batches for our network. The idea is that it grabs batch_size words from a words list. Then for each of those words, it gets the target words in the window. I haven't found a way to pass in a random number of target words and get it to work with the architecture, so I make one row per input-target pair. This is a generator function by the way, helps save memory.


In [8]:
def get_batches(words, batch_size, window_size=5):
    ''' Create a generator of word batches as a tuple (inputs, targets) '''
    
    n_batches = len(words)//batch_size
    
    # only full batches
    words = words[:n_batches*batch_size]
    
    for idx in range(0, len(words), batch_size):
        x, y = [], []
        batch = words[idx:idx+batch_size]
        for ii in range(len(batch)):
            batch_x = batch[ii]
            batch_y = get_target(batch, ii, window_size)
            y.extend(batch_y)
            x.extend([batch_x]*len(batch_y))
        yield x, y

Building the graph

From Chris McCormick's blog, we can see the general structure of our network.

The input words are passed in as one-hot encoded vectors. This will go into a hidden layer of linear units, then into a softmax layer. We'll use the softmax layer to make a prediction like normal.

The idea here is to train the hidden layer weight matrix to find efficient representations for our words. We can discard the softmax layer becuase we don't really care about making predictions with this network. We just want the embedding matrix so we can use it in other networks we build from the dataset.

I'm going to have you build the graph in stages now. First off, creating the inputs and labels placeholders like normal.

Exercise: Assign inputs and labels using tf.placeholder. We're going to be passing in integers, so set the data types to tf.int32. The batches we're passing in will have varying sizes, so set the batch sizes to [None]. To make things work later, you'll need to set the second dimension of labels to None or 1.


In [9]:
train_graph = tf.Graph()
with train_graph.as_default():
    inputs = tf.placeholder(tf.int32, [None], name='inputs')
    labels = tf.placeholder(tf.int32, [None, None], name='labels')

Embedding

The embedding matrix has a size of the number of words by the number of units in the hidden layer. So, if you have 10,000 words and 300 hidden units, the matrix will have size $10,000 \times 300$. Remember that we're using tokenized data for our inputs, usually as integers, where the number of tokens is the number of words in our vocabulary.

Exercise: Tensorflow provides a convenient function tf.nn.embedding_lookup that does this lookup for us. You pass in the embedding matrix and a tensor of integers, then it returns rows in the matrix corresponding to those integers. Below, set the number of embedding features you'll use (200 is a good start), create the embedding matrix variable, and use tf.nn.embedding_lookup to get the embedding tensors. For the embedding matrix, I suggest you initialize it with a uniform random numbers between -1 and 1 using tf.random_uniform.


In [10]:
n_vocab = len(int_to_vocab)
n_embedding = 200 # Number of embedding features 
with train_graph.as_default():
    embedding = tf.Variable(tf.random_uniform((n_vocab, n_embedding), -1, 1))
    embed = tf.nn.embedding_lookup(embedding, inputs)

Negative sampling

For every example we give the network, we train it using the output from the softmax layer. That means for each input, we're making very small changes to millions of weights even though we only have one true example. This makes training the network very inefficient. We can approximate the loss from the softmax layer by only updating a small subset of all the weights at once. We'll update the weights for the correct label, but only a small number of incorrect labels. This is called "negative sampling". Tensorflow has a convenient function to do this, tf.nn.sampled_softmax_loss.

Exercise: Below, create weights and biases for the softmax layer. Then, use tf.nn.sampled_softmax_loss to calculate the loss. Be sure to read the documentation to figure out how it works.


In [11]:
# Number of negative labels to sample
n_sampled = 100
with train_graph.as_default():
    softmax_w = tf.Variable(tf.truncated_normal((n_vocab, n_embedding), stddev=0.1))
    softmax_b = tf.Variable(tf.zeros(n_vocab))
    
    # Calculate the loss using negative sampling
    loss = tf.nn.sampled_softmax_loss(softmax_w, softmax_b, 
                                      labels, embed,
                                      n_sampled, n_vocab)
    
    cost = tf.reduce_mean(loss)
    optimizer = tf.train.AdamOptimizer().minimize(cost)

Validation

This code is from Thushan Ganegedara's implementation. Here we're going to choose a few common words and few uncommon words. Then, we'll print out the closest words to them. It's a nice way to check that our embedding table is grouping together words with similar semantic meanings.


In [12]:
with train_graph.as_default():
    ## From Thushan Ganegedara's implementation
    valid_size = 16 # Random set of words to evaluate similarity on.
    valid_window = 100
    # pick 8 samples from (0,100) and (1000,1100) each ranges. lower id implies more frequent 
    valid_examples = np.array(random.sample(range(valid_window), valid_size//2))
    valid_examples = np.append(valid_examples, 
                               random.sample(range(1000,1000+valid_window), valid_size//2))

    valid_dataset = tf.constant(valid_examples, dtype=tf.int32)
    
    # We use the cosine distance:
    norm = tf.sqrt(tf.reduce_sum(tf.square(embedding), 1, keep_dims=True))
    normalized_embedding = embedding / norm
    valid_embedding = tf.nn.embedding_lookup(normalized_embedding, valid_dataset)
    similarity = tf.matmul(valid_embedding, tf.transpose(normalized_embedding))

In [ ]:
# If the checkpoints directory doesn't exist:
!mkdir checkpoints


mkdir: cannot create directory ‘checkpoints’: File exists

In [ ]:
epochs = 10
batch_size = 1000
window_size = 10

with train_graph.as_default():
    saver = tf.train.Saver()

with tf.Session(graph=train_graph) as sess:
    iteration = 1
    loss = 0
    sess.run(tf.global_variables_initializer())

    for e in range(1, epochs+1):
        batches = get_batches(train_words, batch_size, window_size)
        start = time.time()
        for x, y in batches:
            
            feed = {inputs: x,
                    labels: np.array(y)[:, None]}
            train_loss, _ = sess.run([cost, optimizer], feed_dict=feed)
            
            loss += train_loss
            
            if iteration % 100 == 0: 
                end = time.time()
                print("Epoch {}/{}".format(e, epochs),
                      "Iteration: {}".format(iteration),
                      "Avg. Training loss: {:.4f}".format(loss/100),
                      "{:.4f} sec/batch".format((end-start)/100))
                loss = 0
                start = time.time()
            
            if iteration % 1000 == 0:
                # note that this is expensive (~20% slowdown if computed every 500 steps)
                sim = similarity.eval()
                for i in range(valid_size):
                    valid_word = int_to_vocab[valid_examples[i]]
                    top_k = 8 # number of nearest neighbors
                    nearest = (-sim[i, :]).argsort()[1:top_k+1]
                    log = 'Nearest to %s:' % valid_word
                    for k in range(top_k):
                        close_word = int_to_vocab[nearest[k]]
                        log = '%s %s,' % (log, close_word)
                    print(log)
            
            iteration += 1
    save_path = saver.save(sess, "checkpoints/text8.ckpt")
    embed_mat = sess.run(normalized_embedding)


Epoch 1/10 Iteration: 100 Avg. Training loss: 5.6102 0.0995 sec/batch
Epoch 1/10 Iteration: 200 Avg. Training loss: 5.6119 0.0983 sec/batch
Epoch 1/10 Iteration: 300 Avg. Training loss: 5.5103 0.0984 sec/batch
Epoch 1/10 Iteration: 400 Avg. Training loss: 5.5998 0.0984 sec/batch
Epoch 1/10 Iteration: 500 Avg. Training loss: 5.4934 0.0990 sec/batch
Epoch 1/10 Iteration: 600 Avg. Training loss: 5.5582 0.0987 sec/batch
Epoch 1/10 Iteration: 700 Avg. Training loss: 5.5375 0.0985 sec/batch
Epoch 1/10 Iteration: 800 Avg. Training loss: 5.5585 0.0986 sec/batch
Epoch 1/10 Iteration: 900 Avg. Training loss: 5.5058 0.0989 sec/batch
Epoch 1/10 Iteration: 1000 Avg. Training loss: 5.4330 0.0983 sec/batch
Nearest to often: cetra, suite, jonathon, boleslav, relator, superb, geographia, dredging,
Nearest to many: subband, pathogenesis, fifth, dbase, unsympathetic, boleyn, passionately, wil,
Nearest to state: heathland, ido, fellin, schadeberg, credits, widescreen, skilfully, exothermic,
Nearest to six: chengdu, parry, resund, tubules, formalism, thousand, jun, maldivians,
Nearest to three: pays, chasen, xenophon, show, roam, enthusiasms, taxonomically, satisfy,
Nearest to four: postulate, raman, aachen, flatness, plains, starvation, truthfulness, lleyton,
Nearest to more: hennig, blacklisting, postulated, dependents, visualized, uneconomic, warehouse, unsettling,
Nearest to have: shipmates, deceitful, leyden, vivien, coordinate, abertay, cirencester, italo,
Nearest to defense: brentano, fungal, lacan, zakopane, trilobite, medvedev, byu, america,
Nearest to operations: austrians, academics, jagger, mutagenic, messier, affray, superconductivity, visibility,
Nearest to pre: blacklisting, maiman, bull, whomever, arouse, resented, adleman, despoiled,
Nearest to consists: machine, mavericks, shamanic, cet, caretaker, unpredictability, spotless, guest,
Nearest to heavy: peirce, plane, drafted, unrealistic, partements, humberto, buns, remaining,
Nearest to pressure: blockage, up, negated, plaguing, diaper, aamir, peculiarly, rewrote,
Nearest to magazine: neutronic, anselmo, stage, politically, thermonuclear, mokhehle, floating, kristeva,
Nearest to pope: minter, refraining, clinched, foreskin, terri, forman, kampen, sever,
Epoch 1/10 Iteration: 1100 Avg. Training loss: 5.4905 0.0983 sec/batch
Epoch 1/10 Iteration: 1200 Avg. Training loss: 5.3998 0.0970 sec/batch
Epoch 1/10 Iteration: 1300 Avg. Training loss: 5.3708 0.0968 sec/batch
Epoch 1/10 Iteration: 1400 Avg. Training loss: 5.2466 0.0962 sec/batch
Epoch 1/10 Iteration: 1500 Avg. Training loss: 5.2165 0.0976 sec/batch
Epoch 1/10 Iteration: 1600 Avg. Training loss: 5.1793 0.0969 sec/batch
Epoch 1/10 Iteration: 1700 Avg. Training loss: 5.1281 0.0966 sec/batch
Epoch 1/10 Iteration: 1800 Avg. Training loss: 5.0715 0.0952 sec/batch
Epoch 1/10 Iteration: 1900 Avg. Training loss: 5.0118 0.0953 sec/batch
Epoch 1/10 Iteration: 2000 Avg. Training loss: 4.9863 0.0967 sec/batch
Nearest to often: suite, superb, establishes, capitalized, fungi, levi, strict, cetra,
Nearest to many: fifth, subband, pathogenesis, europe, for, integers, adding, still,
Nearest to state: heathland, an, fellin, rule, biased, twisting, seemed, widescreen,
Nearest to six: chengdu, thousand, parry, formalism, wish, instability, hardcore, obliquely,
Nearest to three: show, pays, xenophon, satisfy, loss, administered, image, roam,
Nearest to four: postulate, plains, aachen, raman, starvation, fired, skulls, t,
Nearest to more: postulated, hennig, blacklisting, influence, minutes, visualized, vienna, wegener,
Nearest to have: vivien, deceitful, abertay, italo, nearly, coordinate, task, history,
Nearest to defense: brentano, america, fungal, outgoing, trilobite, issue, lacan, byu,
Nearest to operations: academics, austrians, mutagenic, visibility, watch, possible, vested, grants,
Nearest to pre: blacklisting, bull, resented, maiman, arouse, stored, whomever, preserving,
Nearest to consists: machine, need, tribal, north, guest, net, editor, cet,
Nearest to heavy: peirce, remaining, plane, drafted, partements, corresponds, dominating, unrealistic,
Nearest to pressure: up, blockage, attached, requirements, diaper, remembrance, plaguing, epithet,
Nearest to magazine: stage, politically, floating, version, anselmo, appreciation, victoria, korps,
Nearest to pope: minter, foreskin, clinched, refraining, recurs, sever, terri, masterfully,
Epoch 1/10 Iteration: 2100 Avg. Training loss: 4.9263 0.0987 sec/batch
Epoch 1/10 Iteration: 2200 Avg. Training loss: 4.9064 0.0975 sec/batch
Epoch 1/10 Iteration: 2300 Avg. Training loss: 4.8963 0.0978 sec/batch
Epoch 1/10 Iteration: 2400 Avg. Training loss: 4.8471 0.0966 sec/batch
Epoch 1/10 Iteration: 2500 Avg. Training loss: 4.8263 0.0972 sec/batch
Epoch 1/10 Iteration: 2600 Avg. Training loss: 4.8220 0.0966 sec/batch
Epoch 1/10 Iteration: 2700 Avg. Training loss: 4.7923 0.0962 sec/batch
Epoch 1/10 Iteration: 2800 Avg. Training loss: 4.7948 0.0969 sec/batch
Epoch 1/10 Iteration: 2900 Avg. Training loss: 4.7919 0.0967 sec/batch
Epoch 1/10 Iteration: 3000 Avg. Training loss: 4.7713 0.0959 sec/batch
Nearest to often: suite, cetra, superb, fungi, contemplate, gently, neuter, capitalized,
Nearest to many: pathogenesis, fifth, subband, integers, dbase, holland, dramatically, abnormal,
Nearest to state: an, heathland, rule, fellin, biased, seemed, twisting, credits,
Nearest to six: chengdu, parry, thousand, diary, ridicule, formalism, jun, broadcasting,
Nearest to three: show, pays, xenophon, satisfy, grok, peacekeeping, wiley, administered,
Nearest to four: postulate, raman, skulls, aachen, waterways, starvation, plains, flatness,
Nearest to more: postulated, visualized, vienna, hennig, blacklisting, dependents, circumcision, fractional,
Nearest to have: vivien, deceitful, coordinate, italo, abertay, fourier, des, nearly,
Nearest to defense: brentano, fungal, america, compose, trilobite, outgoing, lacan, byu,
Nearest to operations: academics, austrians, visibility, grants, possible, memoir, watch, jagger,
Nearest to pre: blacklisting, bull, arouse, resented, maiman, stored, whomever, centrist,
Nearest to consists: machine, net, north, shamanic, guam, mavericks, need, tribal,
Nearest to heavy: peirce, plane, drafted, remaining, dominating, partements, google, unrealistic,
Nearest to pressure: up, blockage, absorption, attached, negated, plaguing, militarily, slugs,
Nearest to magazine: stage, politically, appreciation, anselmo, floating, metric, victoria, version,
Nearest to pope: minter, foreskin, clinched, refraining, recurs, sever, masterfully, flirted,
Epoch 1/10 Iteration: 3100 Avg. Training loss: 4.7949 0.0977 sec/batch
Epoch 1/10 Iteration: 3200 Avg. Training loss: 4.7705 0.0964 sec/batch
Epoch 1/10 Iteration: 3300 Avg. Training loss: 4.7133 0.0962 sec/batch
Epoch 1/10 Iteration: 3400 Avg. Training loss: 4.7071 0.0973 sec/batch
Epoch 1/10 Iteration: 3500 Avg. Training loss: 4.7535 0.0969 sec/batch
Epoch 1/10 Iteration: 3600 Avg. Training loss: 4.7085 0.0968 sec/batch
Epoch 1/10 Iteration: 3700 Avg. Training loss: 4.6756 0.0970 sec/batch
Epoch 1/10 Iteration: 3800 Avg. Training loss: 4.7314 0.0961 sec/batch
Epoch 1/10 Iteration: 3900 Avg. Training loss: 4.7327 0.0970 sec/batch
Epoch 1/10 Iteration: 4000 Avg. Training loss: 4.6531 0.0960 sec/batch
Nearest to often: cetra, chera, lege, gently, fungi, jonathon, superb, suite,
Nearest to many: pathogenesis, subband, fifth, zoot, abnormal, integers, dbase, amusing,
Nearest to state: an, heathland, rule, fellin, ido, cs, biased, seemed,
Nearest to six: chengdu, parry, isbn, diary, nine, nativity, broadcasting, jun,
Nearest to three: xenophon, show, bretton, chieftain, two, pays, zero, deaths,
Nearest to four: two, raman, aachen, waterways, skulls, postulate, zero, nativity,
Nearest to more: postulated, visualized, blacklisting, circumcision, dependents, idiot, warehouse, hennig,
Nearest to have: deceitful, vivien, coordinate, fourier, italo, nearly, broker, abertay,
Nearest to defense: brentano, fungal, trilobite, america, medvedev, compose, nederlandse, lacan,
Nearest to operations: academics, austrians, visibility, grants, squeezed, jagger, messier, epiphany,
Nearest to pre: blacklisting, maiman, arouse, resented, bull, whomever, stored, yhwh,
Nearest to consists: machine, mavericks, cet, unpredictability, need, shamanic, spouse, guam,
Nearest to heavy: peirce, drafted, remaining, marginal, plane, unrealistic, partements, katharina,
Nearest to pressure: up, blockage, absorption, attached, negated, rewrote, slugs, requirements,
Nearest to magazine: stage, appreciation, anselmo, thermonuclear, philosophically, metric, victoria, mokhehle,
Nearest to pope: refraining, minter, foreskin, clinched, sever, recurs, flirted, terri,
Epoch 1/10 Iteration: 4100 Avg. Training loss: 4.6588 0.0960 sec/batch
Epoch 1/10 Iteration: 4200 Avg. Training loss: 4.6686 0.0959 sec/batch
Epoch 1/10 Iteration: 4300 Avg. Training loss: 4.6052 0.0960 sec/batch
Epoch 1/10 Iteration: 4400 Avg. Training loss: 4.6176 0.0951 sec/batch
Epoch 1/10 Iteration: 4500 Avg. Training loss: 4.6642 0.0959 sec/batch
Epoch 1/10 Iteration: 4600 Avg. Training loss: 4.6286 0.0962 sec/batch
Epoch 2/10 Iteration: 4700 Avg. Training loss: 4.6103 0.0726 sec/batch
Epoch 2/10 Iteration: 4800 Avg. Training loss: 4.5383 0.0968 sec/batch
Epoch 2/10 Iteration: 4900 Avg. Training loss: 4.5313 0.0971 sec/batch
Epoch 2/10 Iteration: 5000 Avg. Training loss: 4.5147 0.0961 sec/batch
Nearest to often: cetra, doomed, chera, gently, weekday, contemplate, lege, looking,
Nearest to many: pathogenesis, zoot, subband, integers, unsympathetic, skim, allegation, beckenbauer,
Nearest to state: heathland, rule, fellin, an, council, ido, cs, hawthorn,
Nearest to six: nine, two, jun, nativity, chengdu, isbn, one, james,
Nearest to three: two, xenophon, zero, chieftain, show, wiley, deaths, bretton,
Nearest to four: two, nine, raman, seven, zero, aachen, waterways, skulls,
Nearest to more: postulated, visualized, circumcision, dependents, hennig, blacklisting, turboprops, minutes,
Nearest to have: vivien, coordinate, deceitful, terminology, fourier, italo, mati, abertay,
Nearest to defense: brentano, america, medvedev, fungal, tsk, trilobite, compose, nederlandse,
Nearest to operations: academics, austrians, messier, visibility, mutagenic, grants, squeezed, epiphany,
Nearest to pre: blacklisting, arouse, maiman, resented, villeneuve, strom, yhwh, bull,
Nearest to consists: mavericks, machine, shamanic, spotless, spouse, unpredictability, need, enumeration,
Nearest to heavy: peirce, drafted, plane, marginal, lamar, remaining, foolish, yielding,
Nearest to pressure: up, absorption, blockage, attached, rewrote, negated, slugs, ink,
Nearest to magazine: stage, appreciation, thermonuclear, anselmo, metric, korps, philosophically, version,
Nearest to pope: refraining, minter, foreskin, flirted, terri, forman, fleur, sever,
Epoch 2/10 Iteration: 5100 Avg. Training loss: 4.4970 0.0992 sec/batch
Epoch 2/10 Iteration: 5200 Avg. Training loss: 4.5189 0.0973 sec/batch
Epoch 2/10 Iteration: 5300 Avg. Training loss: 4.4480 0.0969 sec/batch
Epoch 2/10 Iteration: 5400 Avg. Training loss: 4.5457 0.0963 sec/batch
Epoch 2/10 Iteration: 5500 Avg. Training loss: 4.5048 0.0968 sec/batch
Epoch 2/10 Iteration: 5600 Avg. Training loss: 4.4723 0.0972 sec/batch
Epoch 2/10 Iteration: 5700 Avg. Training loss: 4.4811 0.0973 sec/batch
Epoch 2/10 Iteration: 5800 Avg. Training loss: 4.4298 0.0978 sec/batch
Epoch 2/10 Iteration: 5900 Avg. Training loss: 4.4178 0.0973 sec/batch
Epoch 2/10 Iteration: 6000 Avg. Training loss: 4.4089 0.0964 sec/batch
Nearest to often: cetra, chera, relator, weekday, capitalized, doomed, lege, mediated,
Nearest to many: pathogenesis, zoot, amphetamine, skim, dbase, subband, integers, allegation,
Nearest to state: council, rule, heathland, fellin, gime, hawthorn, geographically, cs,
Nearest to six: two, jun, est, nine, chengdu, isbn, interviewer, broadcasting,
Nearest to three: two, zero, xenophon, chieftain, wiley, bretton, km, deaths,
Nearest to four: two, zero, raman, aachen, waterways, skulls, seven, nine,
Nearest to more: visualized, postulated, dependents, blacklisting, utf, idiot, minutes, turboprops,
Nearest to have: terminology, vivien, coordinate, mati, deceitful, radiology, cadres, spontaneously,
Nearest to defense: brentano, medvedev, america, fungal, tsk, nederlandse, trilobite, persuading,
Nearest to operations: academics, visibility, possible, mutagenic, squeezed, austrians, messier, duh,
Nearest to pre: blacklisting, arouse, maiman, resented, villeneuve, yhwh, manufacturer, strom,
Nearest to consists: mavericks, spotless, machine, shamanic, unpredictability, north, cet, farmland,
Nearest to heavy: peirce, lamar, remaining, marginal, foolish, plane, yielding, katharina,
Nearest to pressure: up, absorption, blockage, attached, negated, nuts, ink, downplays,
Nearest to magazine: stage, appreciation, anselmo, thermonuclear, korps, reggie, metric, philosophically,
Nearest to pope: refraining, flirted, minter, foreskin, terri, forman, sever, fleur,
Epoch 2/10 Iteration: 6100 Avg. Training loss: 4.4361 0.0979 sec/batch
Epoch 2/10 Iteration: 6200 Avg. Training loss: 4.4359 0.0970 sec/batch
Epoch 2/10 Iteration: 6300 Avg. Training loss: 4.4401 0.1014 sec/batch
Epoch 2/10 Iteration: 6400 Avg. Training loss: 4.3908 0.1011 sec/batch
Epoch 2/10 Iteration: 6500 Avg. Training loss: 4.4307 0.1005 sec/batch
Epoch 2/10 Iteration: 6600 Avg. Training loss: 4.4395 0.0999 sec/batch
Epoch 2/10 Iteration: 6700 Avg. Training loss: 4.3953 0.0999 sec/batch
Epoch 2/10 Iteration: 6800 Avg. Training loss: 4.3937 0.1006 sec/batch
Epoch 2/10 Iteration: 6900 Avg. Training loss: 4.4075 0.1007 sec/batch
Epoch 2/10 Iteration: 7000 Avg. Training loss: 4.3983 0.0998 sec/batch
Nearest to often: lege, cetra, mediated, superb, relator, weekday, kohoutek, array,
Nearest to many: pathogenesis, dbase, zoot, skim, amphetamine, subband, shearing, impasse,
Nearest to state: rule, council, fellin, cs, gime, biased, exothermic, heathland,
Nearest to six: two, est, jun, nine, interviewer, isbn, zero, chengdu,
Nearest to three: two, zero, wiley, xenophon, chieftain, km, nov, seven,
Nearest to four: two, zero, aachen, raman, seven, waterways, nine, nativity,
Nearest to more: visualized, postulated, utf, blacklisting, dependents, turboprops, idiot, minutes,
Nearest to have: terminology, vivien, leyden, deceitful, freshman, irda, cadres, spontaneously,
Nearest to defense: brentano, medvedev, america, tsk, persuading, fungal, nederlandse, trilobite,
Nearest to operations: visibility, academics, squeezed, duh, tecnol, austrians, possible, mutagenic,
Nearest to pre: blacklisting, arouse, resented, villeneuve, maiman, strom, twelver, sui,
Nearest to consists: mavericks, unpredictability, north, machine, spotless, cet, enumeration, shamanic,
Nearest to heavy: peirce, yielding, marginal, remaining, lamar, foolish, compounds, katharina,
Nearest to pressure: up, absorption, attached, ink, blockage, nuts, slugs, negated,
Nearest to magazine: stage, appreciation, reggie, anselmo, version, asner, metric, neutronic,
Nearest to pope: refraining, forman, flirted, minter, foreskin, schism, terri, sever,
Epoch 2/10 Iteration: 7100 Avg. Training loss: 4.3811 0.1007 sec/batch
Epoch 2/10 Iteration: 7200 Avg. Training loss: 4.4175 0.0997 sec/batch
Epoch 2/10 Iteration: 7300 Avg. Training loss: 4.3850 0.0994 sec/batch
Epoch 2/10 Iteration: 7400 Avg. Training loss: 4.3672 0.0998 sec/batch
Epoch 2/10 Iteration: 7500 Avg. Training loss: 4.3723 0.1002 sec/batch
Epoch 2/10 Iteration: 7600 Avg. Training loss: 4.3488 0.0993 sec/batch
Epoch 2/10 Iteration: 7700 Avg. Training loss: 4.4007 0.0994 sec/batch
Epoch 2/10 Iteration: 7800 Avg. Training loss: 4.3711 0.1001 sec/batch
Epoch 2/10 Iteration: 7900 Avg. Training loss: 4.3162 0.1001 sec/batch
Epoch 2/10 Iteration: 8000 Avg. Training loss: 4.3688 0.1002 sec/batch
Nearest to often: relator, lege, superb, mediated, capitalized, cetra, fungi, doomed,
Nearest to many: pathogenesis, zoot, ascribing, impasse, dbase, skim, allegation, amphetamine,
Nearest to state: rule, council, gime, fellin, ido, cs, an, biased,
Nearest to six: two, est, interviewer, netherland, zero, nine, one, nativity,
Nearest to three: two, zero, wiley, km, xenophon, seven, dbase, chieftain,
Nearest to four: two, zero, seven, aachen, raman, waterways, nine, nativity,
Nearest to more: visualized, postulated, blacklisting, utf, idiot, minutes, turboprops, dependents,
Nearest to have: cadres, leyden, terminology, deceitful, freshman, radiology, xiith, people,
Nearest to defense: brentano, medvedev, america, tsk, nederlandse, persuading, handicapped, trilobite,
Nearest to operations: squeezed, academics, visibility, tecnol, duh, grants, tas, austrians,
Nearest to pre: blacklisting, arouse, villeneuve, maiman, sui, strom, resented, yhwh,
Nearest to consists: mavericks, unpredictability, north, cet, transuranic, farmland, spotless, shamanic,
Nearest to heavy: peirce, compounds, marginal, yielding, remaining, lamar, dominating, foolish,
Nearest to pressure: up, attached, absorption, blockage, ink, wire, negated, slugs,
Nearest to magazine: stage, appreciation, reggie, anselmo, asner, allis, version, metric,
Nearest to pope: refraining, schism, foreskin, patriarch, sever, minter, forman, presbyterian,
Epoch 2/10 Iteration: 8100 Avg. Training loss: 4.3511 0.1031 sec/batch
Epoch 2/10 Iteration: 8200 Avg. Training loss: 4.3030 0.0987 sec/batch
Epoch 2/10 Iteration: 8300 Avg. Training loss: 4.3694 0.0985 sec/batch
Epoch 2/10 Iteration: 8400 Avg. Training loss: 4.3644 0.0969 sec/batch
Epoch 2/10 Iteration: 8500 Avg. Training loss: 4.3672 0.0986 sec/batch
Epoch 2/10 Iteration: 8600 Avg. Training loss: 4.2831 0.0967 sec/batch
Epoch 2/10 Iteration: 8700 Avg. Training loss: 4.2749 0.0961 sec/batch
Epoch 2/10 Iteration: 8800 Avg. Training loss: 4.3563 0.0985 sec/batch
Epoch 2/10 Iteration: 8900 Avg. Training loss: 4.2086 0.0985 sec/batch
Epoch 2/10 Iteration: 9000 Avg. Training loss: 4.2755 0.0979 sec/batch
Nearest to often: relator, superb, capitalized, lege, doomed, fungi, mediated, array,
Nearest to many: pathogenesis, skim, shearing, zoot, ascribing, dbase, amphetamine, beckenbauer,
Nearest to state: rule, council, gime, an, geographically, cs, biased, ido,
Nearest to six: two, one, zero, nine, est, eight, four, interviewer,
Nearest to three: two, zero, wiley, seven, one, five, eight, xenophon,
Nearest to four: two, zero, seven, eight, nine, aachen, five, six,
Nearest to more: visualized, postulated, utf, blacklisting, dependents, minutes, turboprops, mustard,
Nearest to have: cadres, radiology, terminology, deceitful, xiith, freshman, anaesthesia, contradicted,
Nearest to defense: persuading, medvedev, tsk, nederlandse, brentano, america, handicapped, trilobite,
Nearest to operations: squeezed, grants, academics, dramatically, tecnol, lapu, duh, rationals,
Nearest to pre: arouse, blacklisting, enantiomers, twelver, adleman, maiman, villeneuve, sui,
Nearest to consists: mavericks, unpredictability, north, cet, transuranic, asclepius, farmland, breakage,
Nearest to heavy: marginal, peirce, compounds, dominating, yielding, remaining, foolish, plane,
Nearest to pressure: up, attached, absorption, slugs, wire, ink, blockage, negated,
Nearest to magazine: stage, appreciation, version, asner, reggie, allis, austroasiatic, anselmo,
Nearest to pope: refraining, schism, patriarch, foreskin, forman, sever, minter, terri,
Epoch 2/10 Iteration: 9100 Avg. Training loss: 4.3179 0.0991 sec/batch
Epoch 2/10 Iteration: 9200 Avg. Training loss: 4.3013 0.0970 sec/batch
Epoch 3/10 Iteration: 9300 Avg. Training loss: 4.3384 0.0466 sec/batch
Epoch 3/10 Iteration: 9400 Avg. Training loss: 4.2593 0.0963 sec/batch
Epoch 3/10 Iteration: 9500 Avg. Training loss: 4.2192 0.0975 sec/batch
Epoch 3/10 Iteration: 9600 Avg. Training loss: 4.2322 0.0983 sec/batch
Epoch 3/10 Iteration: 9700 Avg. Training loss: 4.2344 0.1011 sec/batch
Epoch 3/10 Iteration: 9800 Avg. Training loss: 4.2089 0.0998 sec/batch
Epoch 3/10 Iteration: 9900 Avg. Training loss: 4.2264 0.1007 sec/batch
Epoch 3/10 Iteration: 10000 Avg. Training loss: 4.1877 0.0992 sec/batch
Nearest to often: relator, superb, doomed, capitalized, tulare, fungi, lege, mediated,
Nearest to many: pathogenesis, skim, zoot, dbase, shearing, ascribing, amphetamine, whereof,
Nearest to state: rule, council, gime, biased, an, cs, eeoc, ido,
Nearest to six: two, one, zero, nine, est, eight, four, three,
Nearest to three: two, zero, wiley, one, seven, five, eight, six,
Nearest to four: two, zero, seven, six, eight, aachen, five, raman,
Nearest to more: visualized, postulated, utf, idiot, blacklisting, turboprops, keyword, dependents,
Nearest to have: radiology, cadres, deceitful, spontaneously, leyden, xiith, mati, supervisory,
Nearest to defense: tsk, persuading, handicapped, brentano, nederlandse, guided, medvedev, america,
Nearest to operations: rationals, squeezed, tecnol, duh, visibility, messier, academics, tactical,
Nearest to pre: blacklisting, arouse, twelver, enantiomers, adleman, laudatory, sui, villeneuve,
Nearest to consists: mavericks, unpredictability, north, cet, enumeration, transuranic, byproducts, asclepius,
Nearest to heavy: marginal, compounds, peirce, dominating, yielding, remaining, antitank, coastal,
Nearest to pressure: up, attached, absorption, slugs, wire, ink, blockage, negated,
Nearest to magazine: stage, appreciation, reggie, asner, version, rocker, allis, austroasiatic,
Nearest to pope: patriarch, refraining, schism, foreskin, coptic, sever, forman, minter,
Epoch 3/10 Iteration: 10100 Avg. Training loss: 4.2521 0.1026 sec/batch
Epoch 3/10 Iteration: 10200 Avg. Training loss: 4.2208 0.1013 sec/batch
Epoch 3/10 Iteration: 10300 Avg. Training loss: 4.2406 0.1009 sec/batch
Epoch 3/10 Iteration: 10400 Avg. Training loss: 4.1081 0.1008 sec/batch
Epoch 3/10 Iteration: 10500 Avg. Training loss: 4.1814 0.1006 sec/batch
Epoch 3/10 Iteration: 10600 Avg. Training loss: 4.1591 0.1007 sec/batch
Epoch 3/10 Iteration: 10700 Avg. Training loss: 4.1617 0.1003 sec/batch
Epoch 3/10 Iteration: 10800 Avg. Training loss: 4.1812 0.1013 sec/batch
Epoch 3/10 Iteration: 10900 Avg. Training loss: 4.1959 0.1022 sec/batch
Epoch 3/10 Iteration: 11000 Avg. Training loss: 4.1732 0.1002 sec/batch
Nearest to often: superb, capitalized, relator, mediated, tulare, array, hue, curiosity,
Nearest to many: pathogenesis, skim, dbase, pretty, shearing, prefixed, zoot, amphetamine,
Nearest to state: rule, gime, cs, council, biased, eeoc, ido, constitutional,
Nearest to six: two, zero, one, nine, est, four, eight, three,
Nearest to three: two, zero, five, one, wiley, seven, eight, six,
Nearest to four: two, zero, seven, six, eight, five, raman, one,
Nearest to more: visualized, utf, keyword, idiot, blacklisting, specifies, warehouse, hearty,
Nearest to have: radiology, deceitful, cadres, life, anaesthesia, freshman, leyden, spontaneously,
Nearest to defense: tsk, handicapped, persuading, guided, brentano, medvedev, nederlandse, volunteer,
Nearest to operations: rationals, duh, dramatically, squeezed, theta, tactical, visibility, lapu,
Nearest to pre: arouse, blacklisting, twelver, enantiomers, laudatory, embellishment, sui, strom,
Nearest to consists: unpredictability, mavericks, north, enumeration, cet, transuranic, breakage, byproducts,
Nearest to heavy: marginal, dominating, compounds, yielding, remaining, antitank, peirce, coastal,
Nearest to pressure: up, absorption, attached, ink, blockage, slugs, wire, negated,
Nearest to magazine: appreciation, reggie, stage, asner, rocker, version, allis, sidgwick,
Nearest to pope: patriarch, refraining, schism, foreskin, sever, coptic, papal, minter,
Epoch 3/10 Iteration: 11100 Avg. Training loss: 4.1629 0.1019 sec/batch
Epoch 3/10 Iteration: 11200 Avg. Training loss: 4.2371 0.1002 sec/batch
Epoch 3/10 Iteration: 11300 Avg. Training loss: 4.2051 0.1004 sec/batch
Epoch 3/10 Iteration: 11400 Avg. Training loss: 4.1652 0.0985 sec/batch
Epoch 3/10 Iteration: 11500 Avg. Training loss: 4.1723 0.0978 sec/batch
Epoch 3/10 Iteration: 11600 Avg. Training loss: 4.1916 0.0987 sec/batch
Epoch 3/10 Iteration: 11700 Avg. Training loss: 4.2066 0.1012 sec/batch
Epoch 3/10 Iteration: 11800 Avg. Training loss: 4.1521 0.1010 sec/batch
Epoch 3/10 Iteration: 11900 Avg. Training loss: 4.1603 0.0989 sec/batch
Epoch 3/10 Iteration: 12000 Avg. Training loss: 4.1658 0.1003 sec/batch
Nearest to often: superb, capitalized, relator, gifted, tulare, curiosity, array, doomed,
Nearest to many: pathogenesis, skim, dbase, shearing, prefixed, zoot, whereof, amusing,
Nearest to state: rule, cs, exothermic, eben, eeoc, gime, an, biased,
Nearest to six: two, one, zero, nine, four, est, eight, three,
Nearest to three: zero, two, one, five, seven, eight, wiley, six,
Nearest to four: two, zero, seven, eight, one, six, five, nine,
Nearest to more: visualized, idiot, utf, blacklisting, locked, keyword, postulated, enabled,
Nearest to have: freshman, deceitful, iskcon, leyden, abnormality, cadres, radiology, instant,
Nearest to defense: tsk, guided, persuading, handicapped, brentano, turbojet, medvedev, nederlandse,
Nearest to operations: rationals, duh, tactical, dramatically, theta, heralding, lapu, tecnol,
Nearest to pre: arouse, blacklisting, twelver, embellishment, laudatory, enantiomers, sui, wikibook,
Nearest to consists: unpredictability, mavericks, north, cet, enumeration, breakage, byproducts, transuranic,
Nearest to heavy: dominating, marginal, compounds, remaining, yielding, antitank, coastal, foolish,
Nearest to pressure: up, absorption, attached, ink, slugs, atmosphere, militarily, negated,
Nearest to magazine: appreciation, reggie, stage, sidgwick, asner, dogg, anselmo, rocker,
Nearest to pope: schism, foreskin, refraining, patriarch, sever, coptic, papal, terri,
Epoch 3/10 Iteration: 12100 Avg. Training loss: 4.1995 0.1018 sec/batch
Epoch 3/10 Iteration: 12200 Avg. Training loss: 4.1585 0.1009 sec/batch
Epoch 3/10 Iteration: 12300 Avg. Training loss: 4.1576 0.0993 sec/batch
Epoch 3/10 Iteration: 12400 Avg. Training loss: 4.1930 0.0999 sec/batch
Epoch 3/10 Iteration: 12500 Avg. Training loss: 4.1336 0.0992 sec/batch
Epoch 3/10 Iteration: 12600 Avg. Training loss: 4.1502 0.0998 sec/batch
Epoch 3/10 Iteration: 12700 Avg. Training loss: 4.1819 0.1000 sec/batch
Epoch 3/10 Iteration: 12800 Avg. Training loss: 4.1101 0.1003 sec/batch
Epoch 3/10 Iteration: 12900 Avg. Training loss: 4.2195 0.1005 sec/batch
Epoch 3/10 Iteration: 13000 Avg. Training loss: 4.2186 0.1000 sec/batch
Nearest to often: capitalized, superb, relator, gifted, doomed, tulare, appreciate, dashes,
Nearest to many: pathogenesis, shearing, ascribing, whereof, beckenbauer, skim, jeroboam, amusing,
Nearest to state: rule, gime, an, council, vice, cs, eeoc, mayor,
Nearest to six: two, one, zero, nine, eight, four, three, five,
Nearest to three: zero, two, one, eight, five, seven, wiley, six,
Nearest to four: two, zero, eight, seven, one, six, five, nine,
Nearest to more: blacklisting, idiot, influence, visualized, utf, vienna, zeppelin, keyword,
Nearest to have: freshman, cadres, deceitful, leyden, abnormality, iskcon, radiology, instant,
Nearest to defense: persuading, guided, tsk, brentano, handicapped, nederlandse, insisted, medvedev,
Nearest to operations: rationals, lapu, dramatically, tactical, duh, tecnol, implicit, warfare,
Nearest to pre: arouse, embellishment, blacklisting, laudatory, wikibook, twelver, sui, enantiomers,
Nearest to consists: unpredictability, mavericks, cet, north, asclepius, agnostic, transuranic, mount,
Nearest to heavy: marginal, dominating, antitank, yielding, compounds, remaining, peirce, coastal,
Nearest to pressure: up, absorption, attached, slugs, ink, militarily, negated, atmosphere,
Nearest to magazine: appreciation, reggie, sidgwick, asner, rocker, allis, dogg, anselmo,
Nearest to pope: schism, patriarch, foreskin, refraining, papal, electors, decreed, coptic,
Epoch 3/10 Iteration: 13100 Avg. Training loss: 4.2232 0.1019 sec/batch
Epoch 3/10 Iteration: 13200 Avg. Training loss: 4.1134 0.1002 sec/batch
Epoch 3/10 Iteration: 13300 Avg. Training loss: 4.1253 0.1006 sec/batch
Epoch 3/10 Iteration: 13400 Avg. Training loss: 4.1610 0.1004 sec/batch
Epoch 3/10 Iteration: 13500 Avg. Training loss: 4.0222 0.1004 sec/batch
Epoch 3/10 Iteration: 13600 Avg. Training loss: 4.1410 0.1011 sec/batch
Epoch 3/10 Iteration: 13700 Avg. Training loss: 4.1442 0.0996 sec/batch
Epoch 3/10 Iteration: 13800 Avg. Training loss: 4.1417 0.0998 sec/batch
Epoch 4/10 Iteration: 13900 Avg. Training loss: 4.1922 0.0221 sec/batch
Epoch 4/10 Iteration: 14000 Avg. Training loss: 4.1069 0.0989 sec/batch
Nearest to often: capitalized, superb, dashes, relator, array, generally, appreciate, gifted,
Nearest to many: pathogenesis, shearing, skim, ascribing, dbase, congestion, beckenbauer, zoot,
Nearest to state: rule, cs, vice, largest, exothermic, council, coler, greetings,
Nearest to six: two, one, zero, nine, eight, four, five, seven,
Nearest to three: zero, two, one, five, eight, seven, wiley, six,
Nearest to four: two, zero, eight, seven, six, one, five, nine,
Nearest to more: utf, visualized, influence, enabled, turboprops, blacklisting, keyword, rafts,
Nearest to have: cadres, instant, abnormality, radiology, leyden, freshman, iskcon, foreleg,
Nearest to defense: guided, persuading, tsk, handicapped, brentano, turbojet, nederlandse, insisted,
Nearest to operations: rationals, dramatically, lapu, tactical, heralding, tecnol, duh, experts,
Nearest to pre: arouse, embellishment, twelver, wikibook, sui, blacklisting, enantiomers, laudatory,
Nearest to consists: unpredictability, north, cet, mavericks, agnostic, transuranic, enumeration, byproducts,
Nearest to heavy: antitank, marginal, dominating, compounds, remaining, yielding, robotic, ral,
Nearest to pressure: up, attached, absorption, slugs, ink, militarily, fluorine, atmosphere,
Nearest to magazine: appreciation, asner, reggie, sidgwick, allis, dogg, rocker, austroasiatic,
Nearest to pope: schism, foreskin, refraining, papal, patriarch, sever, decreed, electors,
Epoch 4/10 Iteration: 14100 Avg. Training loss: 4.0906 0.1011 sec/batch

Restore the trained network if you need to:


In [ ]:
with train_graph.as_default():
    saver = tf.train.Saver()

with tf.Session(graph=train_graph) as sess:
    saver.restore(sess, tf.train.latest_checkpoint('checkpoints'))
    embed_mat = sess.run(embedding)

Visualizing the word vectors

Below we'll use T-SNE to visualize how our high-dimensional word vectors cluster together. T-SNE is used to project these vectors into two dimensions while preserving local stucture. Check out this post from Christopher Olah to learn more about T-SNE and other ways to visualize high-dimensional data.


In [ ]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

In [ ]:
viz_words = 500
tsne = TSNE()
embed_tsne = tsne.fit_transform(embed_mat[:viz_words, :])

In [139]:
fig, ax = plt.subplots(figsize=(14, 14))
for idx in range(viz_words):
    plt.scatter(*embed_tsne[idx, :], color='steelblue')
    plt.annotate(int_to_vocab[idx], (embed_tsne[idx, 0], embed_tsne[idx, 1]), alpha=0.7)