gensim logo

gensim
gensim tagline

Get Expert Help

• machine learning, NLP, data mining

• custom SW design, development, optimizations

• corporate trainings & IT consulting

scripts.word2vec2tensor – Convert the word2vec format to Tensorflow 2D tensor

scripts.word2vec2tensor – Convert the word2vec format to Tensorflow 2D tensor

USAGE: $ python -m gensim.scripts.word2vec2tensor –input <Word2Vec model file> –output <TSV tensor filename prefix> [–binary] <Word2Vec binary flag>

Where:

  • <Word2Vec model file>: Input Word2Vec model.
  • <TSV tensor filename prefix>: 2D tensor TSV output file name prefix.
  • <Word2Vec binary flag>: Set True if Word2Vec model is binary. Defaults to False.
Output:
The script will create two TSV files. A 2d tensor format file, and a Word Embedding metadata file. Both files will use the –output file name as prefix.

This script is used to convert the word2vec format to Tensorflow 2D tensor and metadata formats for Embedding Visualization To use the generated TSV 2D tensor and metadata file in the Projector Visualizer, please

  1. Open http://projector.tensorflow.org/.
  2. Choose “Load Data” from the left menu.
  3. Select “Choose file” in “Load a TSV file of vectors.” and choose you local “_tensor.tsv” file.
  4. Select “Choose file” in “Load a TSV file of metadata.” and choose you local “_metadata.tsv” file.

For more information about TensorBoard TSV format please visit: https://www.tensorflow.org/versions/master/how_tos/embedding_viz/

gensim.scripts.word2vec2tensor.word2vec2tensor(word2vec_model_path, tensor_filename, binary=False)

Convert Word2Vec mode to 2D tensor TSV file and metadata file

Parameters:
  • word2vec_model_path (str) – word2vec model file path.
  • tensor_filename (str) – filename prefix.
  • binary (bool) – set True to use a binary Word2Vec model, defaults to False.