CS224d L2 word2vec

2018-07-12  本文已影响0人  gb_QA_log

title: CS224d L2 word2vec
date: 2017-03-26 19:18:29
categories: NLP/CS224d
mathjax: true
tags: [CS224d,NLP]


1 WordNet

2 “one-hot” representation

x_{2}= \begin{bmatrix} 0\\ 0\\ 0\\ 1\\ 0\\ \end{bmatrix}

存在问题:

3 distributional similarity based representation

3.1 full documents vs window size of(5~10)

inverted fille index 倒排文件索引【魏骁勇教授网络数据挖掘

3.2 问题

3.3 解决方法:降维

# SVD的实现
import matplotlib.pyplot as plt
import numpy as np
la = np.linalg
words = ["I","like","enjoy",
         "deep","learning","NLP","flying","."]
# I like deep learning.
# I like NLP.
# I enjoy flying.
# windows size is 1
#             I like enjoy deep learning NLP flying
X = np.array([[0,2,1,0,0,0,0,0], # I
             [2,0,0,1,0,1,0,0], # like
             [1,0,0,0,0,0,1,0], # enjoy
             [0,1,0,0,1,0,0,0], # deep
             [0,0,0,1,0,0,0,1], # learning
             [0,1,0,0,0,0,0,1], # NLP
             [0,0,1,0,0,0,0,1], # flying
             [0,0,0,0,1,1,1,0]]) # .
U,s,Vh = la.svd(X,full_matrices=False)
print(U)
plt.xlim(-0.8*1.1,0.2*1.1)
plt.ylim(-0.8*1.1,0.8*1.1)
for i in xrange(len(words)):
    # print(i)
    plt.text(U[i,0],U[i,1],words[i])
plt.show()
output

3.4 the he has 等词的过滤

注:一些有趣的语义Pattern
来源:An improved model of semantic similarity based on lexical co-occurence

3.5 word2vec

因为SVD存在的问题:

提出利用word2vec(Mikolov et al.2013):
目标函数

J(\theta)=\frac{1}{T}\sum_{t=1}^{T}\sum_{-c<=j<=c,j\neq0}logP(w_{t+j}|w_t)
P(w_0|w_t)=\frac{e^{v_{w_0}^{'T}v_{w_i}}}{\sum_{w=1}^{W}e^{v_{w}^{'T}v_{w_i}}}

求导

image.png

3.6 word2vec的线性关系

apple - apples ≈ car - cars

3.7 GloVe

GloVe

Word embedding matrix(词嵌入矩阵),提前训练好的词嵌入矩阵

Appendix

上一篇下一篇

猜你喜欢

热点阅读