Visualise word2vec generated from gensim

后端 未结 2 1979
清歌不尽
清歌不尽 2021-01-31 10:54

I have trained a doc2vec and corresponding word2vec on my own corpus using gensim. I want to visualise the word2vec using t-sne with the words. As in, each dot in the figure has

2条回答
  •  后悔当初
    2021-01-31 11:10

    With the following, you can convert your model to a TSV and then use this page for visualization.

    with open(self.word_tensors_TSV, 'bw') as file_vector, open(self.word_meta_TSV, 'bw') as file_metadata:
        for word in model.wv.vocab:
            file_metadata.write((word + '\n').encode('utf-8', errors='replace'))
            vector_row = '\t'.join(str(x) for x in model[word])
            file_vector.write((vector_row + '\n').encode('utf-8', errors='replace'))
    

    :)

提交回复
热议问题