Download test_embed.py from openagi-agi/V2L-Alpha1-Example1: direct link, hf CLI and curl.
- Browser
- Download file 505 Bytes
-
https://huggingface.co/openagi-agi/V2L-Alpha1-Example1/resolve/main/test_embed.py
- Command line
-
hf download hf://openagi-agi/V2L-Alpha1-Example1/test_embed.py
-
curl -L -o test_embed.py https://huggingface.co/openagi-agi/V2L-Alpha1-Example1/resolve/main/test_embed.py
505 Bytes
| from sentence_transformers import SentenceTransformer | |
| import time | |
| import torch | |
| model = SentenceTransformer("Snowflake/snowflake-arctic-embed-xs", device="cuda") | |
| texts = ["The quick brown fox jumps over the lazy dog."] * 1000 | |
| start = time.time() | |
| embeddings = model.encode( | |
| texts, | |
| batch_size=512, | |
| convert_to_tensor=True, | |
| normalize_embeddings=True, | |
| device="cuda", | |
| torch_dtype=torch.int8 | |
| ) | |
| print(f"⏱️ Embedded 1000 items in {time.time() - start:.2f} seconds") | |