glove 学习

github地址

https://github.com/stanfordnlp/GloVe/tree/master/src

gloVe是和word2vector功能相似的模型,把句子的信息和全局的信息结合,目的是在语义和语句上都获得更好的表达效果,下面我们仅从使用的角度上看gloVe模型

模型目标:进行词的向量化表示,使得向量之间尽可能多地蕴含语义和语法的信息。

  • 输入:语料库
  • 输出:词向量
  • 方法概述:首先基于语料库构建词的共现矩阵,然后基于共现矩阵和GloVe模型学习词向量。
  • To train your own GloVe vectors, first you'll need to prepare your corpus as a single text file with all words separated by a single space. If your corpus has multiple documents, simply concatenate documents together with a single space. If your documents are particularly short, it's possible that padding the gap between documents with e.g. 5 "dummy" words will produce better vectors. Once you create your corpus, you can train GloVe vectors using the following 4 tools. An example is included in demo.sh, which you can modify as necessary.

    This four main tools in this package are:

    1) vocab_count

    This tool requires an input corpus that should already consist of whitespace-separated tokens. Use something like the Stanford Tokenizer first on raw text. From the corpus, it constructs unigram counts from a corpus, and optionally thresholds the resulting vocabulary based on total vocabulary size or minimum frequency count.

    2) cooccur

    Constructs word-word cooccurrence statistics from a corpus. The user should supply a vocabulary file, as produced by vocab_count, and may specify a variety of parameters, as described by running ./build/cooccur.

    3) shuffle

    Shuffles the binary file of cooccurrence statistics produced by cooccur. For large files, the file is automatically split into chunks, each of which is shuffled and stored on disk before being merged and shuffled together. The user may specify a number of parameters, as described by running ./build/shuffle.

    4) glove

    Train the GloVe model on the specified cooccurrence data, which typically will be the output of the shuffle tool. The user should supply a vocabulary file, as given by vocab_count, and may specify a number of other parameters, which are described by running ./build/glove.


  • 下载源代码 需要修改

  • CFLAGS = -lm -pthread -Ofast -march=native -funroll-loops -Wno-unused-result为CFLAGS = -lm -pthread -O2 -march=native -funroll-loops -Wno-unused-result

  • 具体demo.sh执行例子

  1. ./vocab_count -min-count $VOCAB_MIN_COUNT -verbose $VERBOSE < $CORPUS > $VOCAB_FILE  
  2.   
  3. ./cooccur -memory $MEMORY -vocab-file $VOCAB_FILE -verbose $VERBOSE -window-size $WINDOW_SIZE < $CORPUS > $COOCCURRENCE_FILE  
  4.   
  5. ./shuffle -memory $MEMORY -verbose $VERBOSE < $COOCCURRENCE_FILE > $COOCCURRENCE_SHUF_FILE  
  6.   
  7. ./glove -save-file $SAVE_FILE -threads $NUM_THREADS -input-file $COOCCURRENCE_SHUF_FILE -x-max $X_MAX -iter $MAX_ITER -vector-size $VECTOR_SIZE -binary $BINARY -vocab-file $VOCAB_FILE -verbose $VERBOSE  
  8.   
  9. octave -nodisplay -nodesktop -nojvm -nosplash < ./eval/read_and_evaluate.m 1>&2  

  • 语料下载


参考资料地址:https://nlp.stanford.edu/pubs/glove.pdf



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GloVe(Global Vectors)是一种用于自然语言处理的深度学习模型,它通过全局词向量(Global Word Vectors)的方式学习词与词之间的语义关系。GloVe模型的主要思想是通过大量的语料库学习一组共享的词向量,这些词向量能够捕捉到词语之间的语义相似性。 GloVe模型的主要步骤包括: 1. 预处理:对语料库进行分词、去除停用词等预处理操作,以便更好地捕捉词语之间的语义关系。 2. 构建矩阵:将语料库中的每个词与所有其他词进行匹配,构建一个高维的相似性矩阵。 3. 参数估计:通过最小化相似性矩阵中词语对之间的相似度,对模型参数进行估计。这个过程通常采用梯度下降等优化算法进行求解。 4. 生成词向量:通过对每个词进行向量表示,可以捕捉到词语之间的语义关系。这些词向量可以用于后续的自然语言处理任务,如文本分类、情感分析等。 GloVe模型在自然语言处理领域得到了广泛的应用,其优势在于能够捕捉到词语之间的全局语义关系,并且在语料库规模较大时表现较好。GloVe模型对于多语言也具有较好的适应性,并且与其他深度学习模型结合使用,可以进一步提高自然语言处理任务的性能。然而,GloVe模型也存在一些缺点,如计算复杂度较高、需要较大的语料库等。 总的来说,GloVe模型是一种具有广泛应用前景的深度学习模型,它在自然语言处理领域取得了较好的效果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值