Hub documentation

嵌入图谱

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

嵌入图谱

Embedding Atlas 是一款用于探索大型嵌入空间的交互式可视化工具。它支持您可视化、交叉筛选和搜索嵌入及其关联的元数据,帮助您理解高维数据中的模式和关系。所有计算均在您的计算机上完成,确保您的数据保持私密和安全。

以下是作为静态 Space 托管的 MegaScience 数据集的示例图集:

主要功能

  • 交互式探索:通过流畅、响应迅速的可视化界面浏览数百万个嵌入
  • 基于浏览器的计算:在本地计算嵌入和投影,无需将数据发送到外部服务器
  • 交叉筛选:在多个元数据列之间关联并筛选数据
  • 搜索功能:查找与给定查询或现有项目相似的数据点
  • 多种集成选项:可通过命令行、Jupyter 小部件或 Web 界面使用

先决条件

首先,安装 Embedding Atlas:

pip install embedding-atlas

如果您计划从 Hugging Face Hub 加载私有数据集,还需要使用您的 Hugging Face 账户登录:

hf auth login

从 Hub 加载数据集

Embedding Atlas 与 Hugging Face Hub 无缝集成,允许您直接可视化来自任何数据集的嵌入。

使用命令行

通过命令行界面可视化 Hugging Face 数据集是最简单的方法。使用 IMDB 数据集试试:

# Load the IMDB dataset from the Hub
embedding-atlas stanfordnlp/imdb

# Specify the text column for embedding computation
embedding-atlas stanfordnlp/imdb --text "text"

# Load only a sample for faster exploration
embedding-atlas stanfordnlp/imdb --text "text" --sample 5000

对于您自己的数据集,请使用相同的模式:

# Load your dataset from the Hub
embedding-atlas username/dataset-name

# Load multiple splits
embedding-atlas username/dataset-name --split train --split test

# Specify custom text column
embedding-atlas username/dataset-name --text "content"

使用 Python 和 Jupyter

您还可以在 Jupyter notebook 中使用 Embedding Atlas 进行交互式探索:

from embedding_atlas.widget import EmbeddingAtlasWidget
from datasets import load_dataset
import pandas as pd

# Load the IMDB dataset from Hugging Face Hub
dataset = load_dataset("stanfordnlp/imdb", split="train[:5000]")

# Convert to pandas DataFrame
df = dataset.to_pandas()

# Create interactive widget
widget = EmbeddingAtlasWidget(df)
widget

对于您自己的数据集:

from embedding_atlas.widget import EmbeddingAtlasWidget
from datasets import load_dataset
import pandas as pd

# Load your dataset from the Hub
dataset = load_dataset("username/dataset-name", split="train")
df = dataset.to_pandas()

# Create interactive widget
widget = EmbeddingAtlasWidget(df)
widget

使用预计算嵌入

如果您拥有包含预计算嵌入的数据集,可以直接加载它们:

# Load dataset with pre-computed coordinates
embedding-atlas username/dataset-name \
    --x "embedding_x" \
    --y "embedding_y"

# Load with pre-computed nearest neighbors
embedding-atlas username/dataset-name \
    --neighbors "neighbors_column"

自定义嵌入

Embedding Atlas 默认使用 SentenceTransformers,但也支持自定义嵌入模型:

# Use a specific embedding model
embedding-atlas stanfordnlp/imdb \
    --text "text" \
    --model "sentence-transformers/all-MiniLM-L6-v2"

# For models requiring remote code execution
embedding-atlas username/dataset-name \
    --model "custom/model" \
    --trust-remote-code

UMAP 投影参数

针对您的特定用例微调降维:

embedding-atlas stanfordnlp/imdb \
    --text "text" \
    --umap-n-neighbors 30 \
    --umap-min-dist 0.1 \
    --umap-metric "cosine"

用例

探索文本数据集

可视化和探索文本语料库,以识别聚类、异常值和模式:

from embedding_atlas.widget import EmbeddingAtlasWidget
from datasets import load_dataset
import pandas as pd

# Load a text classification dataset
dataset = load_dataset("stanfordnlp/imdb", split="train[:5000]")
df = dataset.to_pandas()

# Visualize with metadata
widget = EmbeddingAtlasWidget(df)
widget

其他资源

Update on GitHub