def word2vec2tensor(word2vec_model_path, tensor_filename, binary=False):
 model = gensim.models.Word2Vec.load_word2vec_format(word2vec_model_path, binary=binary)
 outfiletsv = (tensor_filename + '_tensor.tsv')
 outfiletsvmeta = (tensor_filename + '_metadata.tsv')
 with open(outfiletsv, 'w+') as file_vector:
  with open(outfiletsvmeta, 'w+') as file_metadata:
   for word in model.index2word:
    file_metadata.write((word.encode('utf-8') + '\n'))
    vector_row = ' DCTB '.join(map(str, model[word]))
    file_vector.write((vector_row + '\n'))
 logger.info(('2D tensor file saved to %s' % outfiletsv))
 logger.info(('Tensor metadata file saved to %s' % outfiletsvmeta))

def word2vec2tensor ( word2vec_model_path , tensor_filename , binary = False ) : model = gensim . models . Word2Vec . load_word2vec_format ( word2vec_model_path , binary = binary ) outfiletsv = ( tensor_filename + '_tensor.tsv' ) outfiletsvmeta = ( tensor_filename + '_metadata.tsv' ) with open ( outfiletsv , 'w+' ) as file_vector : with open ( outfiletsvmeta , 'w+' ) as file_metadata : for word in model . index2word : file_metadata . write ( ( word . encode ( 'utf-8' ) + '\n' ) ) vector_row = ' DCTB ' . join ( map ( str , model [ word ] ) ) file_vector . write ( ( vector_row + '\n' ) ) logger . info ( ( '2D tensor file saved to %s' % outfiletsv ) ) logger . info ( ( 'Tensor metadata file saved to %s' % outfiletsvmeta ) )
convert word2vec mode to 2d tensor tsv file and metadata file args: param1 : word2vec model file path param2 : filename prefix param2 : set true to use a binary word2vec model .