word2vec

本文翻译自
本文通过word2vec的“skip-gram and CBOW模型进行深度学习,使用hierarchical softmax 或negative sampling;
训练算法最初是从C包中移植出来,https://code.google.com/archive/p/word2vec/,并且拓展了一些功能;
有一个关于gensim word2vec 的博客教程,使用GoogleNews训练了一个交互式的网络应用,参看

在安装Gensim之前,确保有一个C编译器,用于优化的word2vec训练
初始化一个模型:

>>> model = Word2Vec(sentences, size=100, window=5, min_count=5, workers=4)

把模型保存到磁盘中:

>>> model.save(fname)
>>> model = Word2Vec.load(fname)  # you can continue training with the loaded model!

模型还能够通过磁盘中已存在的word2vec C格式的文件进行实例化

>>> model = Word2Vec.load_word2vec_format('/tmp/vectors.txt', binary=False)  # C text format
>>> model = Word2Vec.load_word2vec_format('/tmp/vectors.bin', binary=True)  # C binary format

你能够使用这个模型进行各种各样的句法/语义信息词任务。其中一些已经被构建:

>>> model.most_similar(positive=['woman', 'king'], negative=['man'])
[('queen', 0.50882536), ...]

>>> model.doesnt_match("breakfast cereal dinner lunch".split())
'cereal'

>>> model.similarity('woman', 'man')
0.73723527

>>> model['computer']  # raw numpy vector of a word
array([-0.00449447, -0.00310097,  0.02421786, ...], dtype=float32)

如果你已经完成了训练(不需要更多的更新,只有查询):

>>> model.init_sims(replace=True)

来修剪不需要的模型记忆,也就是使用更少的内存。
注意:这里有一个模块: gensim.models.phrases它能够让你自动检测到单词数大于一的短语。使用短语,能够训练出包含由多个单词组成的表达式的word2vec模型,例如, new_york_times or financial_crisis:

>>> bigram_transformer = gensim.models.Phrases(sentences)
>>> model = Word2Vec(bigram_transformer[sentences], size=100, ...)

相关文章:
https://arxiv.org/pdf/1301.3781.pdf“>Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient Estimation of Word Representations in Vector Space. In Proceedings of Workshop at ICLR, 2013.

https://papers.nips.cc/paper/5021-distributed-representations-of-words-and-phrases-and-their-compositionality.pdf“>Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, and Jeffrey Dean. Distributed Representations of Words and Phrases and their Compositionality. In Proceedings of NIPS, 2013.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值