Document the GloVe word vector dataset
Browse filesAdd usage, schema, split, preprocessing, and citation documentation while preserving the existing YAML front matter (SHA-256: b599bfb34b3b82e9fb63c02b85b3a8f339052783b19f2edd38997dd1a470e124).
README.md
CHANGED
|
@@ -96,3 +96,111 @@ configs:
|
|
| 96 |
- split: 200d
|
| 97 |
path: twitter27B/200d-*
|
| 98 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
- split: 200d
|
| 97 |
path: twitter27B/200d-*
|
| 98 |
---
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# GloVe Pre-trained Word Vectors
|
| 102 |
+
|
| 103 |
+
该仓库将 GloVe(Global Vectors for Word Representation)预训练词向量整理为 Hugging Face Dataset。每个配置对应一套官方发布语料,每个 split 名称表示词向量维度。
|
| 104 |
+
|
| 105 |
+
## 配置
|
| 106 |
+
|
| 107 |
+
| Config | 语料 | Split / 维度 | 词表大小 |
|
| 108 |
+
| --- | --- | --- | ---: |
|
| 109 |
+
| `6B` | Wikipedia 2014 + Gigaword 5 | `50d`, `100d`, `200d`, `300d` | 400,000 |
|
| 110 |
+
| `42B` | Common Crawl 42B tokens | `300d` | 1,917,494 |
|
| 111 |
+
| `840B` | Common Crawl 840B tokens | `300d` | 2,196,017 |
|
| 112 |
+
| `twitter27B` | Twitter 27B tokens | `25d`, `50d`, `100d`, `200d` | 1,193,514 |
|
| 113 |
+
|
| 114 |
+
全部配置的下载大小合计约为 7.9 GB。只需加载所需配置和维度,无需下载其他向量。
|
| 115 |
+
|
| 116 |
+
## 字段说明
|
| 117 |
+
|
| 118 |
+
每行表示一个 token 及其词向量:
|
| 119 |
+
|
| 120 |
+
- `word`:原始词表中的 token。
|
| 121 |
+
- `vector`:对应的 `float32` 向量;长度由 split 名称决定。
|
| 122 |
+
|
| 123 |
+
例如,`6B` 配置的 `100d` split 中,每个 `vector` 包含 100 个浮点数。
|
| 124 |
+
|
| 125 |
+
## 加载数据
|
| 126 |
+
|
| 127 |
+
加载 `6B` 的全部维度:
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
from datasets import load_dataset
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
dataset = load_dataset("wliafe/glove", "6B")
|
| 134 |
+
print(dataset)
|
| 135 |
+
print(dataset["50d"][0])
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
只加载一个维度:
|
| 139 |
+
|
| 140 |
+
```python
|
| 141 |
+
from datasets import load_dataset
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
vectors = load_dataset(
|
| 145 |
+
"wliafe/glove",
|
| 146 |
+
"twitter27B",
|
| 147 |
+
split="100d",
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
print(vectors.features)
|
| 151 |
+
print(vectors[0]["word"])
|
| 152 |
+
print(len(vectors[0]["vector"]))
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
其他配置示例:
|
| 156 |
+
|
| 157 |
+
```python
|
| 158 |
+
from datasets import load_dataset
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
glove_42b = load_dataset("wliafe/glove", "42B", split="300d")
|
| 162 |
+
glove_840b = load_dataset("wliafe/glove", "840B", split="300d")
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
## 查询词向量
|
| 166 |
+
|
| 167 |
+
`Dataset.filter()` 可以直接查找少量 token,但它会扫描整个 split:
|
| 168 |
+
|
| 169 |
+
```python
|
| 170 |
+
from datasets import load_dataset
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
vectors = load_dataset("wliafe/glove", "6B", split="50d")
|
| 174 |
+
matches = vectors.filter(lambda row: row["word"] == "king")
|
| 175 |
+
|
| 176 |
+
if len(matches) == 0:
|
| 177 |
+
raise KeyError("king 不在词表中")
|
| 178 |
+
|
| 179 |
+
king_vector = matches[0]["vector"]
|
| 180 |
+
print(len(king_vector))
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
频繁查询时,建议一次性建立 token 到行号或向量的索引,并根据内存容量选择所需配置。大型配置不适合无条件转换为完整的 Python 字典。
|
| 184 |
+
|
| 185 |
+
## 使用说明
|
| 186 |
+
|
| 187 |
+
- token 的大小写、标点和分词形式沿用原始 GloVe 文件。
|
| 188 |
+
- 不同配置的词表互不保证一致。
|
| 189 |
+
- split 名称是向量维度,不是训练集或测试集划分。
|
| 190 |
+
- 向量以 `float32` 保存。
|
| 191 |
+
|
| 192 |
+
## 引用
|
| 193 |
+
|
| 194 |
+
如果该数据集对你的研究有帮助,请引用 GloVe:
|
| 195 |
+
|
| 196 |
+
```bibtex
|
| 197 |
+
@inproceedings{pennington2014glove,
|
| 198 |
+
title={GloVe: Global Vectors for Word Representation},
|
| 199 |
+
author={Pennington, Jeffrey and Socher, Richard and Manning, Christopher D.},
|
| 200 |
+
booktitle={Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
|
| 201 |
+
pages={1532--1543},
|
| 202 |
+
year={2014}
|
| 203 |
+
}
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
原始向量、语料说明和使用条款请以 [GloVe 官方项目页面](https://nlp.stanford.edu/projects/glove/) 为准。
|