glove / README.md
wliafe's picture
Document the GloVe word vector dataset (#1)
636bc0f
|
Raw
History Blame Contribute Delete
4.85 kB
metadata
dataset_info:
  - config_name: 42B
    features:
      - name: word
        dtype: string
      - name: vector
        list: float32
    splits:
      - name: 300d
        num_bytes: 2332012426
        num_examples: 1917494
    download_size: 2332049667
    dataset_size: 2332012426
  - config_name: 6B
    features:
      - name: word
        dtype: string
      - name: vector
        list: float32
    splits:
      - name: 50d
        num_bytes: 86156474
        num_examples: 400000
      - name: 100d
        num_bytes: 166156474
        num_examples: 400000
      - name: 200d
        num_bytes: 326156474
        num_examples: 400000
      - name: 300d
        num_bytes: 486156474
        num_examples: 400000
    download_size: 1063792425
    dataset_size: 1064625896
  - config_name: 840B
    features:
      - name: word
        dtype: string
      - name: vector
        list: float32
    splits:
      - name: 300d
        num_bytes: 2670329198
        num_examples: 2196017
    download_size: 2672066809
    dataset_size: 2670329198
  - config_name: twitter27B
    features:
      - name: word
        dtype: string
      - name: vector
        list: float32
    splits:
      - name: 25d
        num_bytes: 141330891
        num_examples: 1193514
      - name: 50d
        num_bytes: 260682291
        num_examples: 1193514
      - name: 100d
        num_bytes: 499385091
        num_examples: 1193514
      - name: 200d
        num_bytes: 976790691
        num_examples: 1193514
    download_size: 1866400394
    dataset_size: 1878188964
configs:
  - config_name: 42B
    data_files:
      - split: 300d
        path: 42B/300d-*
  - config_name: 6B
    data_files:
      - split: 50d
        path: 6B/50d-*
      - split: 100d
        path: 6B/100d-*
      - split: 200d
        path: 6B/200d-*
      - split: 300d
        path: 6B/300d-*
  - config_name: 840B
    data_files:
      - split: 300d
        path: 840B/300d-*
  - config_name: twitter27B
    data_files:
      - split: 25d
        path: twitter27B/25d-*
      - split: 50d
        path: twitter27B/50d-*
      - split: 100d
        path: twitter27B/100d-*
      - split: 200d
        path: twitter27B/200d-*

GloVe Pre-trained Word Vectors

该仓库将 GloVe(Global Vectors for Word Representation)预训练词向量整理为 Hugging Face Dataset。每个配置对应一套官方发布语料,每个 split 名称表示词向量维度。

配置

Config 语料 Split / 维度 词表大小
6B Wikipedia 2014 + Gigaword 5 50d, 100d, 200d, 300d 400,000
42B Common Crawl 42B tokens 300d 1,917,494
840B Common Crawl 840B tokens 300d 2,196,017
twitter27B Twitter 27B tokens 25d, 50d, 100d, 200d 1,193,514

全部配置的下载大小合计约为 7.9 GB。只需加载所需配置和维度,无需下载其他向量。

字段说明

每行表示一个 token 及其词向量:

  • word:原始词表中的 token。
  • vector:对应的 float32 向量;长度由 split 名称决定。

例如,6B 配置的 100d split 中,每个 vector 包含 100 个浮点数。

加载数据

加载 6B 的全部维度:

from datasets import load_dataset


dataset = load_dataset("wliafe/glove", "6B")
print(dataset)
print(dataset["50d"][0])

只加载一个维度:

from datasets import load_dataset


vectors = load_dataset(
    "wliafe/glove",
    "twitter27B",
    split="100d",
)

print(vectors.features)
print(vectors[0]["word"])
print(len(vectors[0]["vector"]))

其他配置示例:

from datasets import load_dataset


glove_42b = load_dataset("wliafe/glove", "42B", split="300d")
glove_840b = load_dataset("wliafe/glove", "840B", split="300d")

查询词向量

Dataset.filter() 可以直接查找少量 token,但它会扫描整个 split:

from datasets import load_dataset


vectors = load_dataset("wliafe/glove", "6B", split="50d")
matches = vectors.filter(lambda row: row["word"] == "king")

if len(matches) == 0:
    raise KeyError("king 不在词表中")

king_vector = matches[0]["vector"]
print(len(king_vector))

频繁查询时,建议一次性建立 token 到行号或向量的索引,并根据内存容量选择所需配置。大型配置不适合无条件转换为完整的 Python 字典。

使用说明

  • token 的大小写、标点和分词形式沿用原始 GloVe 文件。
  • 不同配置的词表互不保证一致。
  • split 名称是向量维度,不是训练集或测试集划分。
  • 向量以 float32 保存。

引用

如果该数据集对你的研究有帮助,请引用 GloVe:

@inproceedings{pennington2014glove,
  title={GloVe: Global Vectors for Word Representation},
  author={Pennington, Jeffrey and Socher, Richard and Manning, Christopher D.},
  booktitle={Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP)},
  pages={1532--1543},
  year={2014}
}

原始向量、语料说明和使用条款请以 GloVe 官方项目页面 为准。