Spaces:
Runtime error
Runtime error
Download code_snippets/08_instructor_embeddings.py from purpleriann/LLM-Engineers-Handbook: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/spaces/purpleriann/LLM-Engineers-Handbook/resolve/main/code_snippets/08_instructor_embeddings.py
- Command line
-
hf download hf://spaces/purpleriann/LLM-Engineers-Handbook/code_snippets/08_instructor_embeddings.py
-
curl -L -o 08_instructor_embeddings.py https://huggingface.co/spaces/purpleriann/LLM-Engineers-Handbook/resolve/main/code_snippets/08_instructor_embeddings.py
652 Bytes
| from sentence_transformers import SentenceTransformer | |
| # Create virtual environment, install dependencies and run the code: | |
| # 1. Create: python3 -m venv instructor_venv | |
| # 2. Activate: source instructor_venv/bin/activate | |
| # 3. Install: pip install sentence-transformers==3.3.0 | |
| # 4. Run the code: python code_snippets/08_instructor_embeddings.py | |
| if __name__ == "__main__": | |
| model = SentenceTransformer("hkunlp/instructor-base") | |
| sentence = "RAG Fundamentals First" | |
| instruction = "Represent the title of an article about AI:" | |
| embeddings = model.encode([[instruction, sentence]]) | |
| print(embeddings.shape) # noqa | |
| # Output: (1, 768) | |