References
- Paper: GloVe: Global Vectors for Word Representation, Pennington, Socher, Manning, 2014.
- Lecture: CS224N Lecture 2.
1. Method Comparison
传统词向量方法有两类:
| 方法类型 | 代表 | 优点 | 缺点 |
|---|---|---|---|
| Count-based | LSA, PPMI | 利用全局统计信息 | 难以捕捉语义关系 |
| Prediction-based | Word2Vec | 捕捉语义关系 | 无法利用全局信息 |
GloVe means Global Vectors. It combines global information from the co-occurrence matrix with a prediction-style optimization objective.
2. Co-occurrence Matrix
2.1 Definition
- : 共现矩阵, 表示词 在词 的上下文窗口中出现的次数.
- : 词 的上下文中所有词的总次数.
- : 词 在词 上下文中出现的概率.
2.2 Features
- Symmetry: 由于不区分词序, 是对称矩阵.
- Sparsity: 大型语料库中, 非常稀疏.
- One-pass construction: 只需扫描语料库一次.
2.3 Dimensionality Reduction: SVD
Theorem (SVD). Any matrix can be decomposed as:
取前 个奇异值得到低秩近似:
Problem. 高频词, 如 “the” and “a”, 影响过大.
Solutions.
- 对数变换: .
- 阈值截断: , .
- 直接忽略.
3. PMI: Pointwise Mutual Information
3.1 PMI Definition
- : 和 正相关, 共现频率高于独立假设.
- : 独立.
- : 负相关, 倾向于不共现.
3.2 PPMI: Positive PMI
只保留正相关, 更稳定.
3.3 SPPMI: Shifted PPMI
其中 是平滑参数.
Note: SGNS as matrix factorization
Skip-gram with negative sampling implicitly factorizes a shifted PMI matrix. Reference: Neural Word Embedding as Implicit Matrix Factorization.
4. GloVe Model
4.1 Core Intuition: Odds Ratio
考虑词 ice 和 steam 的共现概率比:
| Ratio | |||
|---|---|---|---|
| solid | 8.9 > 1 | ||
| gas | 0.085 < 1 | ||
| water | 1.36 approx. 1 | ||
| fashion | 0.96 approx. 1 |
Interpretation:
- Ratio > 1: 与 ice 更相关.
- Ratio < 1: 与 steam 更相关.
- Ratio approx. 1: 与两者关系相似.
4.2 Model Derivation
Goal. Find function such that:
Derivation:
- Difference vector representation.
- Homomorphic property.
- Exponential function.
- Taking log.
- Merge bias terms.
4.3 Loss Function
其中:
- : 权重函数, 抑制高频词影响.
- : 词向量.
- : bias 项.
- 本质是**加权最小二乘法**.
4.4 Weight Function
通常 .
5. GloVe vs Word2Vec
| 特性 | Word2Vec | GloVe |
|---|---|---|
| 方法类型 | Prediction-based | Count-based + Prediction |
| 训练方式 | 滑动窗口, 逐样本 | 全局共现矩阵 |
| 目标函数 | 交叉熵 / 负采样 | 加权最小二乘 |
| 训练效率 | 较慢, 多次扫描 | 较快, 一次构建矩阵 |
| 语义关系 | Yes | Yes |
| 全局信息 | No | Yes |