word2vec

训练中文词向量

ε祈祈猫儿з 提交于 2019-12-19 01:52:35
首先是下载中文维基数据 wget https://dumps.wikimedia.org/zhwiki/latest/zhwiki-latest-pages-articles.xml.bz2 下载提取工具https://github.com/attardi/wikiextractor 运行python WikiExtractor.py -b 5000M -o extracted zhwiki-latest-pages-articles.xml.bz2 安装繁体转简体工具 sudo apt-get install opencc 在extracted子目录下执行繁体转简体 opencc -i wiki_00 -o zhwiki.text -c t2s.json 利用jieba分好词 下载word2vec工具 https://github.com/dav/word2vec 编译word2vec工具,进入到word2vec 目录下 运行命令 make ,再运行命令 cd scripts && ./demo-word.sh 词向量训练 进入bin 文件夹下面,输入 ./word2vec -train 输入语料 -output 输出文件路径 -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -iter 15,等待片刻即可

Tensorflow: Word2vec CBOW model

非 Y 不嫁゛ 提交于 2019-12-18 15:11:10
问题 I am new to tensorflow and to word2vec. I just studied the word2vec_basic.py which trains the model using Skip-Gram algorithm. Now I want to train using CBOW algorithm. Is it true that this can be achieved if I simply reverse the train_inputs and train_labels ? 回答1: I think CBOW model can not simply be achieved by flipping the train_inputs and the train_labels in Skip-gram because CBOW model architecture uses the sum of the vectors of surrounding words as one single instance for the

Using word2vec to classify words in categories

别来无恙 提交于 2019-12-18 11:31:31
问题 BACKGROUND I have vectors with some sample data and each vector has a category name (Places,Colors,Names). ['john','jay','dan','nathan','bob'] -> 'Names' ['yellow', 'red','green'] -> 'Colors' ['tokyo','bejing','washington','mumbai'] -> 'Places' My objective is to train a model that take a new input string and predict which category it belongs to. For example if a new input is "purple" then I should be able to predict 'Colors' as the correct category. If the new input is "Calgary" it should

word2vec: negative sampling (in layman term)?

﹥>﹥吖頭↗ 提交于 2019-12-18 09:54:36
问题 I'm reading the paper below and I have some trouble , understanding the concept of negative sampling. http://arxiv.org/pdf/1402.3722v1.pdf Can anyone help , please? 回答1: The idea of word2vec is to maximise the similarity (dot product) between the vectors for words which appear close together (in the context of each other) in text, and minimise the similarity of words that do not. In equation (3) of the paper you link to, ignore the exponentiation for a moment. You have v_c * v_w -------------

How to use Gensim doc2vec with pre-trained word vectors?

谁说我不能喝 提交于 2019-12-17 17:24:36
问题 I recently came across the doc2vec addition to Gensim. How can I use pre-trained word vectors (e.g. found in word2vec original website) with doc2vec? Or is doc2vec getting the word vectors from the same sentences it uses for paragraph-vector training? Thanks. 回答1: Note that the "DBOW" ( dm=0 ) training mode doesn't require or even create word-vectors as part of the training. It merely learns document vectors that are good at predicting each word in turn (much like the word2vec skip-gram

java深度学习库deeplearning4j使用之word2vec与INDAarry

女生的网名这么多〃 提交于 2019-12-16 09:18:04
import org.deeplearning4j.models.embeddings.loader.WordVectorSerializer; import org.deeplearning4j.models.word2vec.Word2Vec; import org.nd4j.linalg.api.ndarray.INDArray; /** *必须的maven,核心组件、nlp模块、platform *INDArray相当于python的numpy <dependency> <groupId>org.deeplearning4j</groupId> <artifactId>deeplearning4j-core</artifactId> <version>1.0.0-beta4</version> </dependency> <dependency> <groupId>org.nd4j</groupId> <artifactId>nd4j-native-platform</artifactId> <version>1.0.0-beta4</version> </dependency> <dependency> <groupId>org.deeplearning4j</groupId> <artifactId>deeplearning4j-nlp</artifactId>

浅析Word2Vec

烈酒焚心 提交于 2019-12-16 02:08:06
浅析Word2Vec 1 预备内容 1.1 NLP任务 1.2 Distributional Semantics 1.3 one-hot向量 1.4 softmax函数 2 浅析Word2Vec 2.1 概述 2.2 Skip-Gram模型 2.2.1 模型的细节 2.2.2 隐层 2.2.3 输出层 2.2.4 小结 2.3 Continuous Bag of Words模型(CBOW) 2.4 加速策略1——Hierarchical Softmax 2.5 加速策略2——Negative Sampling 2.5.1 Subsampling Frequent Words 2.5.2 负采样 Negative Sampling 2.5.3 选择负样本 2.6 加速策略小结 2.7 模型训练的一些参数设定 参考文献 1 预备内容 1.1 NLP任务 NLP的目标是设计算法让计算机去理解自然语言并去解决某些问题。 所有NLP任务德第一步,就是如何将单词表示为模型的输入。为了使得大多数NLP任务表现良好,我们首先需要能够用向量表示单词的相似性和差异性。有了这些词向量,我们可以简单的用向量自身的能力来计算相似性(如Jaccard, cos等) 1.2 Distributional Semantics A word’s meaning is given by the words that

8.3 特征抽取、转化和选择

一个人想着一个人 提交于 2019-12-16 00:27:37
一、特征抽取 1.TF-IDF “词频-逆向文件频率”(TF-IDF)是一种在文本挖掘中广泛使用的特征向量化方法,它可以体现一个文档中词语在语料库中的重要程度。词语由t表示,文档由d表示,语料库由D表示。 词频TF(t,d) 是词语t在文档d中出现的次数 文件频率DF(t,D) 是包含词语的文档的个数 TF-IDF就是在数值化文档信息,衡量词语能提供多少信息以区分文档 。其定义如下: 在Spark ML库中,TF-IDF被分成两部分: TF (+hashing)【转换器】: HashingTF 是一个Transformer,在文本处理中,接收词条的集合然后把这些集合转化成固定长度的特征向量。这个算法在哈希的同时会统计各个词条的词频。 IDF【评估器】: IDF是一个Estimator,在一个数据集上应用它的fit()方法,产生一个IDFModel。 该IDFModel 接收特征向量(由HashingTF产生),然后计算每一个词在文档中出现的频次。IDF会减少那些在语料库中出现频率较高的词的权重。 过程描述: 在下面的代码段中,我们以一组句子开始 首先使用分解器Tokenizer把句子划分为单个词语 对每一个句子(词袋),使用HashingTF将句子转换为特征向量 最后使用IDF重新调整特征向量(这种转换通常可以提高使用文本特征的性能) (1)导入TF-IDF所需要的包:

自然语言处理库—Gensim之Word2vec

倖福魔咒の 提交于 2019-12-15 10:09:12
1. gensim概述 Gensim(http://pypi.python.org/pypi/gensim)是一款开源的第三方Python工具包,用于从原始的非结构化的文本中,无监督地学习到文本隐层的主题向量表达。 主要用于主题建模和文档相似性处理,它支持包括TF-IDF,LSA,LDA,和word2vec在内的多种主题模型算法。Gensim在诸如获取单词的词向量等任务中非常有用。 使用Gensim训练Word2vec十分方便,训练步骤如下: 1)将语料库预处理:一行一个文档或句子,将文档或句子分词(以空格分割,英文可以不用分词,英文单词之间已经由空格分割,中文预料需要使用分词工具进行分词,常见的分词工具有StandNLP、ICTCLAS、Ansj、FudanNLP、HanLP、结巴分词等); 2)将原始的训练语料转化成一个sentence的迭代器,每一次迭代返回的sentence是一个word(utf8格式)的列表。可以使用Gensim中word2vec.py中的LineSentence()方法实现; 3)将上面处理的结果输入Gensim内建的word2vec对象进行训练即可: from gensim . models import Word2Vec sentences = word2vec . LineSentence ( './in_the_name_of_people

Word2Vec详解

亡梦爱人 提交于 2019-12-14 19:59:42
原文地址:https://www.cnblogs.com/guoyaohua/p/9240336.html 2013年,Google开源了一款用于词向量计算的工具——word2vec,引起了工业界和学术界的关注。首先,word2vec可以在百万数量级的词典和上亿的数据集上进行高效地训练;其次,该工具得到的训练结果——词向量(word embedding),可以很好地度量词与词之间的相似性。随着深度学习(Deep Learning)在自然语言处理中应用的普及,很多人误以为word2vec是一种深度学习算法。其实word2vec算法的背后是一个浅层神经网络。另外需要强调的一点是,word2vec是一个计算word vector的开源工具。当我们在说word2vec算法或模型的时候,其实指的是其背后用于计算word vector的CBoW模型和Skip-gram模型。很多人以为word2vec指的是一个算法或模型,这也是一种谬误。接下来,本文将从统计语言模型出发,尽可能详细地介绍word2vec工具背后的算法模型的来龙去脉。 Statistical Language Model 在深入word2vec算法的细节之前,我们首先回顾一下自然语言处理中的一个基本问题: 如何计算一段文本序列在某种语言下出现的概率?之所为称其为一个基本问题,是因为它在很多NLP任务中都扮演着重要的角色。 例如