Datasets:
Download load_example.py from igriv/dire-arxiv-bge-small-embeddings: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/datasets/igriv/dire-arxiv-bge-small-embeddings/resolve/main/load_example.py
- Command line
-
hf download hf://datasets/igriv/dire-arxiv-bge-small-embeddings/load_example.py
-
curl -L -o load_example.py https://huggingface.co/datasets/igriv/dire-arxiv-bge-small-embeddings/resolve/main/load_example.py
1.46 kB
| #!/usr/bin/env python3 | |
| """Minimal loader for the DiRe arXiv BGE-small embeddings dataset. | |
| Run after `python3 -m pip install datasets numpy pandas`. | |
| """ | |
| import numpy as np | |
| from datasets import load_dataset | |
| REPO = "igriv/dire-arxiv-bge-small-embeddings" # update once HF namespace is finalized | |
| def load_embeddings(): | |
| """Returns (arxiv_ids: np.ndarray[str], X: np.ndarray[float32, (N, 384)]).""" | |
| ds = load_dataset(REPO, split="train") # default config = embeddings | |
| arxiv_ids = np.asarray(ds["arxiv_id"]) | |
| X = np.vstack(ds["embedding"]).astype("float32") | |
| return arxiv_ids, X | |
| def load_metadata(): | |
| """Returns a pandas DataFrame keyed on arxiv_id.""" | |
| return load_dataset(REPO, name="metadata", split="train").to_pandas() | |
| def load_layout(method: str = "dire", n_neighbors: int = 16, d: int = 2): | |
| """Pre-computed full-corpus layout for the requested (method, n, d).""" | |
| config = "layouts_2d" if d == 2 else "layouts_3d" | |
| df = load_dataset(REPO, name=config, split="train").to_pandas() | |
| return df[(df.method == method) & (df.n_neighbors == n_neighbors)].reset_index(drop=True) | |
| if __name__ == "__main__": | |
| ids, X = load_embeddings() | |
| print(f"Embeddings: {X.shape} {X.dtype}, {len(ids)} arxiv_ids") | |
| meta = load_metadata() | |
| print(f"Metadata: {len(meta)} rows; columns = {list(meta.columns)}") | |
| layout = load_layout("dire", 16, 2) | |
| print(f"Canonical DiRe (n=16) 2-d layout: {len(layout)} points") | |