如何使用 word2vec 获取给定单词的词嵌入向量和上下文向量? [英] How to get both the word embeddings vector and context vector of a given word by using word2vec?

查看:48
本文介绍了如何使用 word2vec 获取给定单词的词嵌入向量和上下文向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from gensim.models import word2vec

sentences = word2vec.Text8Corpus('TextFile')
model = word2vec.Word2Vec(sentences, size=200, min_count = 2, workers = 4)
print model['king']

输出向量是'king'的上下文向量还是'king'的词嵌入向量?如何同时获得king"的上下文向量和king"的词嵌入向量?谢谢!

Is the output vector the context vector of 'king' or the word embedding vector of 'king'? How can I get both context vector of 'king' and the word embedding vector of 'king'? Thanks!

推荐答案

它是 'king' 的嵌入向量.

It is the embedding vector for 'king'.

如果使用分层 softmax,则上下文向量为:

If you use hierarchical softmax, the context vectors are:

model.syn1

如果你使用负采样,它们是:

and if you use negative sampling they are:

model.syn1neg

可以通过以下方式访问向量:

The vectors can be accessed by:

model.syn1[model.vocab[word].index]

这篇关于如何使用 word2vec 获取给定单词的词嵌入向量和上下文向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆