Skip to content

Instantly share code, notes, and snippets.

@dipanjanS
Created March 13, 2018 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipanjanS/865248edadb721f754bad10e874a9866 to your computer and use it in GitHub Desktop.
Save dipanjanS/865248edadb721f754bad10e874a9866 to your computer and use it in GitHub Desktop.
from keras.preprocessing.sequence import skipgrams
# generate skip-grams
skip_grams = [skipgrams(wid, vocabulary_size=vocab_size, window_size=10) for wid in wids]
# view sample skip-grams
pairs, labels = skip_grams[0][0], skip_grams[0][1]
for i in range(10):
print("({:s} ({:d}), {:s} ({:d})) -> {:d}".format(
id2word[pairs[i][0]], pairs[i][0],
id2word[pairs[i][1]], pairs[i][1],
labels[i]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment