Sync from davanstrien/uv-scripts via hub-sync
Browse files- generate-embeddings.py +13 -4
generate-embeddings.py
CHANGED
|
@@ -4,11 +4,17 @@
|
|
| 4 |
# "datasets",
|
| 5 |
# "sentence-transformers>=5.0.0",
|
| 6 |
# "torch",
|
|
|
|
| 7 |
# "numpy",
|
| 8 |
# "pillow",
|
| 9 |
# "einops",
|
| 10 |
# "huggingface-hub>=1.12",
|
| 11 |
# ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# ///
|
| 13 |
"""
|
| 14 |
Generate embeddings for a Hugging Face dataset (text OR images) with sentence-transformers,
|
|
@@ -38,23 +44,26 @@ PROMPTS (retrieval correctness — read this):
|
|
| 38 |
Benchmarks (20k rows, seq-cap 512): all-MiniLM-L6-v2 ~900 rows/s on an L4 (~$0.24/1M rows);
|
| 39 |
bge-base-en-v1.5 ~120 rows/s. L4 is the cheapest flavor for these encoder models.
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
Examples:
|
| 42 |
# Text (default). Document convention auto-picked.
|
| 43 |
-
hf jobs uv run
|
| 44 |
stanfordnlp/imdb your-name/imdb-embeddings \\
|
| 45 |
--column text --model sentence-transformers/all-MiniLM-L6-v2
|
| 46 |
|
| 47 |
# e5: docs auto-get "passage: ". (--prompt 'passage: ' would be the explicit form.)
|
| 48 |
-
hf jobs uv run
|
| 49 |
stanfordnlp/imdb your-name/imdb-e5 --model intfloat/multilingual-e5-large
|
| 50 |
|
| 51 |
# Images (CLIP) — prompts don't apply.
|
| 52 |
-
hf jobs uv run
|
| 53 |
your-name/photos your-name/photos-embeddings \\
|
| 54 |
--modality image --column image --model clip-ViT-B-32
|
| 55 |
|
| 56 |
# Test on a small slice first, keep the output private
|
| 57 |
-
hf jobs uv run
|
| 58 |
stanfordnlp/imdb your-name/imdb-emb --max-samples 100 --private
|
| 59 |
|
| 60 |
FAN-OUT (multi-job) MODE:
|
|
|
|
| 4 |
# "datasets",
|
| 5 |
# "sentence-transformers>=5.0.0",
|
| 6 |
# "torch",
|
| 7 |
+
# "torchvision", # multimodal embedders such as embeddinggemma-2 need it to load their processor
|
| 8 |
# "numpy",
|
| 9 |
# "pillow",
|
| 10 |
# "einops",
|
| 11 |
# "huggingface-hub>=1.12",
|
| 12 |
# ]
|
| 13 |
+
#
|
| 14 |
+
# [tool.hf-jobs]
|
| 15 |
+
# flavor = "l4x1"
|
| 16 |
+
# timeout = "1h"
|
| 17 |
+
# secrets = ["HF_TOKEN"]
|
| 18 |
# ///
|
| 19 |
"""
|
| 20 |
Generate embeddings for a Hugging Face dataset (text OR images) with sentence-transformers,
|
|
|
|
| 44 |
Benchmarks (20k rows, seq-cap 512): all-MiniLM-L6-v2 ~900 rows/s on an L4 (~$0.24/1M rows);
|
| 45 |
bge-base-en-v1.5 ~120 rows/s. L4 is the cheapest flavor for these encoder models.
|
| 46 |
|
| 47 |
+
On Jobs, the [tool.hf-jobs] header sets the l4x1 flavor, a 1h timeout and the HF_TOKEN secret
|
| 48 |
+
(`hf` CLI 1.32+). --flavor and --timeout before the script override it.
|
| 49 |
+
|
| 50 |
Examples:
|
| 51 |
# Text (default). Document convention auto-picked.
|
| 52 |
+
hf jobs uv run generate-embeddings.py \\
|
| 53 |
stanfordnlp/imdb your-name/imdb-embeddings \\
|
| 54 |
--column text --model sentence-transformers/all-MiniLM-L6-v2
|
| 55 |
|
| 56 |
# e5: docs auto-get "passage: ". (--prompt 'passage: ' would be the explicit form.)
|
| 57 |
+
hf jobs uv run generate-embeddings.py \\
|
| 58 |
stanfordnlp/imdb your-name/imdb-e5 --model intfloat/multilingual-e5-large
|
| 59 |
|
| 60 |
# Images (CLIP) — prompts don't apply.
|
| 61 |
+
hf jobs uv run generate-embeddings.py \\
|
| 62 |
your-name/photos your-name/photos-embeddings \\
|
| 63 |
--modality image --column image --model clip-ViT-B-32
|
| 64 |
|
| 65 |
# Test on a small slice first, keep the output private
|
| 66 |
+
hf jobs uv run generate-embeddings.py \\
|
| 67 |
stanfordnlp/imdb your-name/imdb-emb --max-samples 100 --private
|
| 68 |
|
| 69 |
FAN-OUT (multi-job) MODE:
|