In [1]:
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import collections
import math
import os
import random
import zipfile

import numpy as np
from six.moves import urllib
from six.moves import xrange  # pylint: disable=redefined-builtin
import tensorflow as tf

# Step 1: Download the data.
url = 'http://mattmahoney.net/dc/'


def maybe_download(filename, expected_bytes):
  """Download a file if not present, and make sure it's the right size."""
  if not os.path.exists(filename):
    filename, _ = urllib.request.urlretrieve(url + filename, filename)
  statinfo = os.stat(filename)
  if statinfo.st_size == expected_bytes:
    print('Found and verified', filename)
  else:
    print(statinfo.st_size)
    raise Exception(
        'Failed to verify ' + filename + '. Can you get to it with a browser?')
  return filename

filename = maybe_download('text8.zip', 31344016)


# Read the data into a list of strings.
def read_data(filename):
  """Extract the first file enclosed in a zip file as a list of words"""
  with zipfile.ZipFile(filename) as f:
    data = tf.compat.as_str(f.read(f.namelist()[0])).split()
  return data

words = read_data(filename)
print('Data size', len(words))

# Step 2: Build the dictionary and replace rare words with UNK token.
vocabulary_size = 50000


def build_dataset(words):
  count = [['UNK', -1]]
  count.extend(collections.Counter(words).most_common(vocabulary_size - 1))
  dictionary = dict()
  for word, _ in count:
    dictionary[word] = len(dictionary)
  data = list()
  unk_count = 0
  for word in words:
    if word in dictionary:
      index = dictionary[word]
    else:
      index = 0  # dictionary['UNK']
      unk_count += 1
    data.append(index)
  count[0][1] = unk_count
  reverse_dictionary = dict(zip(dictionary.values(), dictionary.keys()))
  return data, count, dictionary, reverse_dictionary

data, count, dictionary, reverse_dictionary = build_dataset(words)
del words  # Hint to reduce memory.
print('Most common words (+UNK)', count[:5])
print('Sample data', data[:10], [reverse_dictionary[i] for i in data[:10]])

data_index = 0


# Step 3: Function to generate a training batch for the skip-gram model.
def generate_batch(batch_size, num_skips, skip_window):
  global data_index
  assert batch_size % num_skips == 0
  assert num_skips <= 2 * skip_window
  batch = np.ndarray(shape=(batch_size), dtype=np.int32)
  labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)
  span = 2 * skip_window + 1  # [ skip_window target skip_window ]
  buffer = collections.deque(maxlen=span)
  for _ in range(span):
    buffer.append(data[data_index])
    data_index = (data_index + 1) % len(data)
  for i in range(batch_size // num_skips):
    target = skip_window  # target label at the center of the buffer
    targets_to_avoid = [skip_window]
    for j in range(num_skips):
      while target in targets_to_avoid:
        target = random.randint(0, span - 1)
      targets_to_avoid.append(target)
      batch[i * num_skips + j] = buffer[skip_window]
      labels[i * num_skips + j, 0] = buffer[target]
    buffer.append(data[data_index])
    data_index = (data_index + 1) % len(data)
  # Backtrack a little bit to avoid skipping words in the end of a batch
  data_index = (data_index + len(data) - span) % len(data)
  return batch, labels

batch, labels = generate_batch(batch_size=8, num_skips=2, skip_window=1)
for i in range(8):
  print(batch[i], reverse_dictionary[batch[i]],
        '->', labels[i, 0], reverse_dictionary[labels[i, 0]])


##### new tab #####



# Step 4: Build and train a skip-gram model.

batch_size = 128
embedding_size = 128  # Dimension of the embedding vector.
skip_window = 1       # How many words to consider left and right.
num_skips = 2         # How many times to reuse an input to generate a label.

# We pick a random validation set to sample nearest neighbors. Here we limit the
# validation samples to the words that have a low numeric ID, which by
# construction are also the most frequent.
valid_size = 16     # Random set of words to evaluate similarity on.
valid_window = 100  # Only pick dev samples in the head of the distribution.
valid_examples = np.random.choice(valid_window, valid_size, replace=False)
num_sampled = 64    # Number of negative examples to sample.

graph = tf.Graph()

with graph.as_default():

  # Input data.
  train_inputs = tf.placeholder(tf.int32, shape=[batch_size])
  train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1])
  valid_dataset = tf.constant(valid_examples, dtype=tf.int32)

  # Ops and variables pinned to the CPU because of missing GPU implementation
  with tf.device('/cpu:0'):
    # Look up embeddings for inputs.
    embeddings = tf.Variable(
        tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))
    embed = tf.nn.embedding_lookup(embeddings, train_inputs)

    # Construct the variables for the NCE loss
    nce_weights = tf.Variable(
        tf.truncated_normal([vocabulary_size, embedding_size],
                            stddev=1.0 / math.sqrt(embedding_size)))
    nce_biases = tf.Variable(tf.zeros([vocabulary_size]))

  # Compute the average NCE loss for the batch.
  # tf.nce_loss automatically draws a new sample of the negative labels each
  # time we evaluate the loss.
  loss = tf.reduce_mean(
      tf.nn.nce_loss(weights=nce_weights,
                     biases=nce_biases,
                     labels=train_labels,
                     inputs=embed,
                     num_sampled=num_sampled,
                     num_classes=vocabulary_size))

  # Construct the SGD optimizer using a learning rate of 1.0.
  optimizer = tf.train.GradientDescentOptimizer(1.0).minimize(loss)

  # Compute the cosine similarity between minibatch examples and all embeddings.
  norm = tf.sqrt(tf.reduce_sum(tf.square(embeddings), 1, keep_dims=True))
  normalized_embeddings = embeddings / norm
  valid_embeddings = tf.nn.embedding_lookup(
      normalized_embeddings, valid_dataset)
  similarity = tf.matmul(
      valid_embeddings, normalized_embeddings, transpose_b=True)

  # Add variable initializer.
  init = tf.initialize_all_variables()

# Step 5: Begin training.
num_steps = 100001

#add saver 

checkpoint_dir = "checkpoint/"
checkpoint_file = checkpoint_dir + "/export"
if not os.path.exists(checkpoint_dir):
  os.makedirs(checkpoint_dir)


with tf.Session(graph=graph) as session:
  # We must initialize all variables before we use them.
  init.run()
  print("Initialized")
  saver = tf.train.Saver()

  average_loss = 0
  for step in xrange(num_steps):
    batch_inputs, batch_labels = generate_batch(
        batch_size, num_skips, skip_window)
    feed_dict = {train_inputs: batch_inputs, train_labels: batch_labels}

    # We perform one update step by evaluating the optimizer op (including it
    # in the list of returned values for session.run()
    _, loss_val = session.run([optimizer, loss], feed_dict=feed_dict)
    average_loss += loss_val

    if step % 2000 == 0:
      if step > 0:
        average_loss /= 2000
      # The average loss is an estimate of the loss over the last 2000 batches.
      print("Average loss at step ", step, ": ", average_loss)
      average_loss = 0

    # Note that this is expensive (~20% slowdown if computed every 500 steps)
    if step % 10000 == 0:
      saver.save(session, checkpoint_file)
      tf.train.write_graph(session.graph_def, checkpoint_dir, 'trained_model.pb', as_text=False)
      tf.train.write_graph(session.graph_def, checkpoint_dir, 'trained_model.txt', as_text=True)
      sim = similarity.eval()
      for i in xrange(valid_size):
        valid_word = reverse_dictionary[valid_examples[i]]
        top_k = 8  # number of nearest neighbors
        nearest = (-sim[i, :]).argsort()[1:top_k + 1]
        log_str = "Nearest to %s:" % valid_word
        for k in xrange(top_k):
          close_word = reverse_dictionary[nearest[k]]
          log_str = "%s %s," % (log_str, close_word)
        print(log_str)
  

  final_embeddings = normalized_embeddings.eval()
  model_exporter = exporter.Exporter(saver)
  model_exporter.init(
  session.graph.as_graph_def(),
  named_graph_signatures={
    'inputs': exporter.generic_signature({"features": train_inputs}),
    'outputs': exporter.generic_signature({"similarity": similarity})
  })
  model_exporter.export(FLAGS.model_path, tf.constant(FLAGS.export_version), session)
  print('Done exporting!')
  
  
  
  
  
  
##### new tab #####


  # Step 6: Visualize the embeddings.
  %matplotlib inline

  def plot_with_labels(low_dim_embs, labels, filename='tsne.png'):
    assert low_dim_embs.shape[0] >= len(labels), "More labels than embeddings"
    plt.figure(figsize=(18, 18))  # in inches
    for i, label in enumerate(labels):
      x, y = low_dim_embs[i, :]
      plt.scatter(x, y)
      plt.annotate(label,
                   xy=(x, y),
                   xytext=(5, 2),
                   textcoords='offset points',
                   ha='right',
                   va='bottom')

    plt.savefig(filename)

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

    tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000)
    plot_only = 500
    low_dim_embs = tsne.fit_transform(final_embeddings[:plot_only, :])
    labels = [reverse_dictionary[i] for i in xrange(plot_only)]
    plot_with_labels(low_dim_embs, labels)

  except ImportError:
    print("Please install sklearn, matplotlib, and scipy to visualize embeddings.")


Found and verified text8.zip
Data size 17005207
Most common words (+UNK) [['UNK', 418391], ('the', 1061396), ('of', 593677), ('and', 416629), ('one', 411764)]
Sample data [5241, 3082, 12, 6, 195, 2, 3136, 46, 59, 156] ['anarchism', 'originated', 'as', 'a', 'term', 'of', 'abuse', 'first', 'used', 'against']
3082 originated -> 12 as
3082 originated -> 5241 anarchism
12 as -> 3082 originated
12 as -> 6 a
6 a -> 12 as
6 a -> 195 term
195 term -> 6 a
195 term -> 2 of
WARNING:tensorflow:From <ipython-input-1-f8ac5bb70d35>:189: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
Initialized
Average loss at step  0 :  272.646850586
Nearest to the: problematic, braking, idiomatic, dependant, prophetess, hectare, islamic, bankers,
Nearest to years: risked, photosynthesis, ducktales, renounced, cva, rifle, milliseconds, swivel,
Nearest to people: fleeing, bartholomew, migration, papadopoulos, kodansha, borrelly, olomouc, guild,
Nearest to up: dense, body, rude, targets, sgml, humor, ascetics, glorantha,
Nearest to time: seductive, formaldehyde, cataract, akan, reggae, travellers, wounds, minyan,
Nearest to war: jinnah, marxism, legitimately, comical, harassing, congress, coastal, reigns,
Nearest to after: persia, standardized, interconnects, owing, utopia, transitioning, lagoons, burglar,
Nearest to are: chives, towels, ortiz, deists, juice, resonator, wheelchair, kidnap,
Nearest to first: dried, dillon, eels, upload, latin, larps, eelam, uniform,
Nearest to six: insight, buy, levitt, depletion, hartley, federline, minted, regent,
Nearest to between: deutsches, fractured, amulet, reconciling, hovering, behind, insensible, haram,
Nearest to from: nobility, mutable, slowly, teleportation, questionnaire, suburb, calgary, reduce,
Nearest to than: catalonia, nrsv, gross, vukovar, baserunner, antithesis, location, eta,
Nearest to history: hyllus, clerics, thing, tess, ambiguous, dislike, promulgated, bonds,
Nearest to four: normandie, heath, terence, wordplay, additional, backstage, cho, confrontation,
Nearest to use: dyson, difficulty, agm, isaac, guessed, interrogating, philosophies, vladislav,
Average loss at step  2000 :  113.3603298
Average loss at step  4000 :  52.9293303332
Average loss at step  6000 :  33.4279969199
Average loss at step  8000 :  23.4267913487
Average loss at step  10000 :  17.8999743264
Nearest to the: a, one, bckgr, this, UNK, ep, its, an,
Nearest to years: photosynthesis, rifle, practical, gathered, gland, jewish, neurons, catholic,
Nearest to people: fleeing, migration, kg, anyone, archie, resemble, bartholomew, autism,
Nearest to up: dense, body, aspiration, january, ashes, humor, starship, other,
Nearest to time: travellers, wounds, archie, outright, asserts, badges, renamed, fao,
Nearest to war: mctaggart, congress, lymphoma, archie, gland, marxism, coastal, traditionally,
Nearest to after: of, persia, learned, tubing, governors, stylistic, in, computers,
Nearest to are: is, were, floated, larger, vs, gallery, eight, cc,
Nearest to first: eels, of, latin, uniform, dried, sales, enter, earth,
Nearest to six: nine, zero, lymphoma, two, bckgr, mathbf, basins, gland,
Nearest to between: behind, phi, bead, gilles, reagents, n, divided, andr,
Nearest to from: in, nobility, pleasant, reduce, and, suburb, asceticism, drivers,
Nearest to than: gross, detail, implementing, june, zorn, triple, greene, corner,
Nearest to history: thing, phi, ar, invention, ambiguous, promulgated, kabul, bonds,
Nearest to four: one, eight, three, nine, two, archie, zero, bckgr,
Nearest to use: difficulty, isaac, philosophies, winter, law, mercury, post, boat,
Average loss at step  12000 :  13.8386477786
Average loss at step  14000 :  11.9024160672
Average loss at step  16000 :  9.96013335586
Average loss at step  18000 :  8.60074739563
Average loss at step  20000 :  7.94282388937
Nearest to the: a, his, its, one, this, operatorname, agouti, an,
Nearest to years: photosynthesis, gathered, rifle, practical, gland, swivel, two, renounced,
Nearest to people: anyone, dasyprocta, bartholomew, fleeing, migration, kg, archie, resemble,
Nearest to up: dense, body, starship, january, meals, aspiration, targets, humor,
Nearest to time: operatorname, dasyprocta, travellers, agouti, renamed, cataract, asserts, outright,
Nearest to war: mctaggart, congress, natasha, lymphoma, dasyprocta, archie, gnat, gland,
Nearest to after: in, of, persia, tubing, standardized, operatorname, learned, with,
Nearest to are: were, is, was, have, had, agouti, wattle, ferruccio,
Nearest to first: acacia, uniform, eels, adder, sales, latin, of, dasyprocta,
Nearest to six: nine, eight, zero, seven, five, dasyprocta, two, four,
Nearest to between: operatorname, behind, in, phi, nine, of, bead, gilles,
Nearest to from: in, of, and, by, operatorname, reduce, napster, tsarevich,
Nearest to than: and, gross, detail, triple, gigantic, implementing, nine, or,
Nearest to history: thing, invention, ambiguous, reversal, ar, phi, agouti, trilogy,
Nearest to four: eight, nine, zero, two, seven, three, six, one,
Nearest to use: difficulty, isaac, dasyprocta, operatorname, law, philosophies, winter, affectionate,
Average loss at step  22000 :  7.09265566003
Average loss at step  24000 :  6.86774852049
Average loss at step  26000 :  6.72189115947
Average loss at step  28000 :  6.41819784164
Average loss at step  30000 :  5.89585284185
Nearest to the: its, their, his, this, a, agouti, amalthea, operatorname,
Nearest to years: photosynthesis, cfa, gathered, two, practical, swivel, rifle, gland,
Nearest to people: fleeing, anyone, migration, bartholomew, dasyprocta, chalukyas, archie, kg,
Nearest to up: starship, body, dense, targets, january, mdi, abakan, amalthea,
Nearest to time: operatorname, dasyprocta, formaldehyde, travellers, cataract, outright, agouti, asserts,
Nearest to war: congress, natasha, mctaggart, akh, lymphoma, gnat, dasyprocta, noumenon,
Nearest to after: in, for, abet, operatorname, tubing, six, with, persia,
Nearest to are: were, is, have, was, rossi, be, had, agouti,
Nearest to first: acacia, uniform, eels, abet, adder, dasyprocta, agouti, sales,
Nearest to six: eight, nine, four, seven, five, zero, three, dasyprocta,
Nearest to between: operatorname, in, behind, with, phi, by, remainder, through,
Nearest to from: in, by, and, of, operatorname, at, agouti, through,
Nearest to than: and, or, nine, gross, liberty, gigantic, detail, triple,
Nearest to history: invention, ambiguous, state, thing, stray, promulgated, reversal, trilogy,
Nearest to four: eight, six, three, five, seven, two, nine, zero,
Nearest to use: difficulty, isaac, abet, dasyprocta, mishnayot, operatorname, law, mercury,
Average loss at step  32000 :  5.99242867982
Average loss at step  34000 :  5.6805022372
Average loss at step  36000 :  5.77872790241
Average loss at step  38000 :  5.52903526163
Average loss at step  40000 :  5.27816747296
Nearest to the: its, their, amalthea, this, a, zero, his, ep,
Nearest to years: cfa, photosynthesis, gathered, practical, swivel, gland, four, rifle,
Nearest to people: fleeing, migration, anyone, zero, bartholomew, athanasian, archie, dasyprocta,
Nearest to up: starship, body, targets, mdi, amalthea, demonic, abakan, dense,
Nearest to time: operatorname, dasyprocta, formaldehyde, laminal, travellers, agouti, cataract, outright,
Nearest to war: natasha, congress, mctaggart, akh, blonde, animals, gnat, noumenon,
Nearest to after: in, abet, six, operatorname, four, for, when, tubing,
Nearest to are: were, is, have, was, zero, rossi, barbarossa, nirvana,
Nearest to first: acacia, uniform, eels, abet, adder, dasyprocta, sales, second,
Nearest to six: eight, four, five, seven, three, zero, nine, two,
Nearest to between: operatorname, in, with, behind, remainder, phi, through, drummond,
Nearest to from: in, by, of, operatorname, and, agouti, zero, through,
Nearest to than: or, and, liberty, implementing, nine, gross, gigantic, detail,
Nearest to history: state, invention, stray, ambiguous, promulgated, agouti, trilogy, thing,
Nearest to four: six, eight, five, three, seven, zero, two, one,
Nearest to use: difficulty, isaac, kifl, abet, agm, mishnayot, dasyprocta, operatorname,
Average loss at step  42000 :  5.39292644775
Average loss at step  44000 :  5.26344004643
Average loss at step  46000 :  5.23817001617
Average loss at step  48000 :  5.22270813525
Average loss at step  50000 :  4.99501055086
Nearest to the: its, their, his, this, a, amalthea, any, agouti,
Nearest to years: cfa, gathered, photosynthesis, rifle, swivel, practical, owl, renounced,
Nearest to people: fleeing, dasyprocta, migration, archie, anyone, athanasian, albury, unwanted,
Nearest to up: starship, body, targets, mdi, amalthea, demonic, abakan, back,
Nearest to time: operatorname, dasyprocta, formaldehyde, laminal, travellers, agouti, effected, cataract,
Nearest to war: natasha, congress, akh, blonde, mctaggart, gnat, noumenon, marxism,
Nearest to after: when, four, in, abet, six, operatorname, dasyprocta, agouti,
Nearest to are: were, is, have, was, franchisee, nirvana, rossi, be,
Nearest to first: acacia, second, uniform, abet, eels, agouti, past, adder,
Nearest to six: eight, four, five, seven, three, nine, two, one,
Nearest to between: in, operatorname, with, three, behind, through, seven, phi,
Nearest to from: in, through, of, by, and, operatorname, at, napster,
Nearest to than: or, liberty, and, nine, implementing, gigantic, gross, wedge,
Nearest to history: state, invention, agouti, promulgated, stray, ambiguous, thing, trilogy,
Nearest to four: three, six, five, eight, seven, two, one, zero,
Nearest to use: difficulty, kifl, isaac, abet, agm, mishnayot, dasyprocta, operatorname,
Average loss at step  52000 :  5.05391303957
Average loss at step  54000 :  5.16286998701
Average loss at step  56000 :  5.05605612588
Average loss at step  58000 :  5.03664448965
Average loss at step  60000 :  4.93702504182
Nearest to the: its, their, ursus, his, a, ep, four, operatorname,
Nearest to years: cfa, gathered, photosynthesis, six, practical, owl, four, gland,
Nearest to people: fleeing, joram, archie, dasyprocta, athanasian, three, ursus, albury,
Nearest to up: back, amalthea, body, mdi, targets, demonic, starship, abakan,
Nearest to time: operatorname, dasyprocta, formaldehyde, laminal, zimri, travellers, uz, agouti,
Nearest to war: natasha, akh, congress, blonde, animals, noumenon, gnat, priory,
Nearest to after: when, four, ursus, six, abet, operatorname, five, before,
Nearest to are: were, is, have, franchisee, be, nirvana, ursus, barbarossa,
Nearest to first: thibetanus, acacia, second, microsite, abet, agouti, ursus, dasyprocta,
Nearest to six: eight, four, seven, five, three, nine, dasyprocta, ursus,
Nearest to between: in, with, operatorname, behind, through, microsite, ursus, drummond,
Nearest to from: in, through, by, and, ursus, operatorname, at, under,
Nearest to than: or, and, ursus, liberty, marko, nine, gigantic, implementing,
Nearest to history: state, thibetanus, agouti, invention, promulgated, pleading, stray, thing,
Nearest to four: five, six, three, eight, seven, two, nine, ursus,
Nearest to use: difficulty, kifl, agm, abet, isaac, mishnayot, ursus, dasyprocta,
Average loss at step  62000 :  5.01486476278
Average loss at step  64000 :  4.84247618276
Average loss at step  66000 :  4.60652961373
Average loss at step  68000 :  4.97275817966
Average loss at step  70000 :  4.91369898152
Nearest to the: their, its, his, this, ursus, amalthea, microcebus, a,
Nearest to years: days, cfa, four, gland, gathered, six, two, five,
Nearest to people: fleeing, joram, albury, athanasian, dasyprocta, consuming, archie, ursus,
Nearest to up: back, amalthea, mdi, off, targets, body, demonic, abakan,
Nearest to time: operatorname, dasyprocta, formaldehyde, laminal, uz, zimri, travellers, wounds,
Nearest to war: natasha, animals, akh, blonde, noumenon, gnat, priory, congress,
Nearest to after: when, before, in, ursus, operatorname, abet, but, was,
Nearest to are: were, is, have, be, barbarossa, rossi, franchisee, was,
Nearest to first: thibetanus, acacia, second, microsite, cebus, abet, agouti, past,
Nearest to six: four, eight, five, seven, three, nine, two, zero,
Nearest to between: with, in, behind, through, operatorname, remainder, microsite, drummond,
Nearest to from: in, through, mico, operatorname, under, ursus, into, napster,
Nearest to than: or, and, liberty, ursus, gross, wedge, but, marko,
Nearest to history: microcebus, state, thibetanus, agouti, pleading, thaler, stray, invention,
Nearest to four: six, five, three, eight, seven, two, nine, one,
Nearest to use: difficulty, kifl, agm, abet, mishnayot, isaac, ursus, dasyprocta,
Average loss at step  72000 :  4.74640291393
Average loss at step  74000 :  4.81608502209
Average loss at step  76000 :  4.72131585956
Average loss at step  78000 :  4.79024813384
Average loss at step  80000 :  4.78119775915
Nearest to the: their, its, a, ursus, amalthea, his, agouti, this,
Nearest to years: days, cfa, gathered, gland, four, owl, seven, drums,
Nearest to people: UNK, joram, fleeing, athanasian, consuming, unwanted, cloaca, albury,
Nearest to up: back, off, mdi, amalthea, body, demonic, starship, targets,
Nearest to time: operatorname, dasyprocta, formaldehyde, laminal, zimri, ursus, goo, uz,
Nearest to war: natasha, animals, akh, noumenon, blonde, priory, congress, gnat,
Nearest to after: when, before, operatorname, abet, ursus, in, meets, was,
Nearest to are: were, is, have, include, franchisee, rossi, nirvana, barbarossa,
Nearest to first: second, thibetanus, acacia, microsite, cebus, last, agouti, abet,
Nearest to six: seven, four, five, eight, three, nine, two, one,
Nearest to between: with, in, through, operatorname, behind, romany, of, iit,
Nearest to from: in, through, by, mico, into, under, ursus, operatorname,
Nearest to than: or, and, liberty, but, ursus, ordeal, gross, nine,
Nearest to history: microcebus, state, list, thibetanus, pleading, agouti, interviews, promulgated,
Nearest to four: six, five, seven, three, eight, two, nine, zero,
Nearest to use: difficulty, kifl, mishnayot, agm, abet, isaac, vladislav, ursus,
Average loss at step  82000 :  4.77002532816
Average loss at step  84000 :  4.7386478287
Average loss at step  86000 :  4.7661146456
Average loss at step  88000 :  4.73886070371
Average loss at step  90000 :  4.76079121995
Nearest to the: its, their, a, this, his, any, ursus, microcebus,
Nearest to years: days, cfa, five, drums, owl, seven, cabinda, heterodox,
Nearest to people: joram, unwanted, athanasian, women, fleeing, consuming, spaceship, cloaca,
Nearest to up: back, off, mdi, amalthea, down, demonic, water, them,
Nearest to time: operatorname, dasyprocta, laminal, formaldehyde, uz, year, globemaster, travellers,
Nearest to war: natasha, animals, akh, blonde, noumenon, gnat, congress, priory,
Nearest to after: when, before, was, six, during, operatorname, ursus, abet,
Nearest to are: were, have, is, include, be, barbarossa, franchisee, nirvana,
Nearest to first: second, thibetanus, acacia, cebus, microsite, last, chosenness, past,
Nearest to six: eight, seven, five, four, nine, three, zero, ursus,
Nearest to between: with, in, through, operatorname, behind, romany, iit, drummond,
Nearest to from: in, through, mico, jati, by, operatorname, ursus, under,
Nearest to than: or, but, and, liberty, ursus, ordeal, sixteenth, for,
Nearest to history: microcebus, state, list, agouti, pleading, thibetanus, promulgated, thaler,
Nearest to four: five, seven, three, six, eight, two, nine, one,
Nearest to use: kifl, difficulty, mishnayot, abet, dasyprocta, ursus, agm, operatorname,
Average loss at step  92000 :  4.66995356667
Average loss at step  94000 :  4.71529757512
Average loss at step  96000 :  4.69613084185
Average loss at step  98000 :  4.58770015717
Average loss at step  100000 :  4.69299576533
Nearest to the: its, their, a, ursus, any, his, amalthea, agouti,
Nearest to years: days, cfa, five, drums, hours, owl, decades, months,
Nearest to people: women, spaceship, unwanted, albury, joram, chymotrypsin, consuming, cloaca,
Nearest to up: off, back, down, amalthea, demonic, mdi, water, them,
Nearest to time: operatorname, dasyprocta, year, globemaster, uz, agouti, ursus, laminal,
Nearest to war: natasha, blonde, animals, noumenon, gnat, congress, priory, akh,
Nearest to after: before, when, during, operatorname, was, at, meets, abet,
Nearest to are: were, is, have, include, be, arrhenius, while, barbarossa,
Nearest to first: second, thibetanus, acacia, last, cebus, microsite, same, chosenness,
Nearest to six: seven, eight, five, four, three, nine, ursus, dasyprocta,
Nearest to between: with, in, through, operatorname, iit, romany, remainder, behind,
Nearest to from: in, through, mico, into, under, jati, operatorname, ursus,
Nearest to than: or, but, and, ursus, liberty, ordeal, mishnayot, gross,
Nearest to history: microcebus, list, agouti, thibetanus, state, pleading, thaler, promulgated,
Nearest to four: five, seven, three, eight, six, two, zero, nine,
Nearest to use: kifl, difficulty, mishnayot, abet, dasyprocta, ursus, agm, operatorname,
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-f8ac5bb70d35> in <module>()
    242 
    243   final_embeddings = normalized_embeddings.eval()
--> 244   model_exporter = exporter.Exporter(saver)
    245   model_exporter.init(
    246   session.graph.as_graph_def(),

NameError: name 'exporter' is not defined

In [ ]: