Skip to content

Instantly share code, notes, and snippets.

@awentzonline
Created May 18, 2016 20:33
Show Gist options
  • Select an option

  • Save awentzonline/a2aab7537eef4cb2b3da78913072d7e7 to your computer and use it in GitHub Desktop.

Select an option

Save awentzonline/a2aab7537eef4cb2b3da78913072d7e7 to your computer and use it in GitHub Desktop.
import sys
import numpy as np
import six
# HACK: this should live in a directory alongside the skip-thoughts project
sys.path.append('../skip-thoughts')
import skipthoughts
import decoding.tools
def mse(a, b):
return np.sum(np.square(a - b)) / a.shape[0]
n_dims = 4800
v_this = v_original = np.random.uniform(0, 1, (n_dims,)).astype('float32')
enc_model = skipthoughts.load_model()
dec_model = decoding.tools.load_model()
for i in range(20):
text = decoding.tools.run_sampler(dec_model, v_this, beam_width=1, stochastic=False, use_unk=False)
print(text)
v_restored = skipthoughts.encode(enc_model, text)[0]
print('mse:', mse(v_original, v_restored))
v_this = v_restored
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment