Spaces:
Build error
Build error
Download src/vectorizer.py from lazarr19/prompt-engine: direct link, hf CLI and curl.
- Browser
- Download file 653 Bytes
-
https://huggingface.co/spaces/lazarr19/prompt-engine/resolve/main/src/vectorizer.py
- Command line
-
hf download hf://spaces/lazarr19/prompt-engine/src/vectorizer.py
-
curl -L -o vectorizer.py https://huggingface.co/spaces/lazarr19/prompt-engine/resolve/main/src/vectorizer.py
653 Bytes
| from typing import Sequence | |
| import numpy as np | |
| class Vectorizer: | |
| def __init__(self, model) -> None: | |
| """Initialize the vectorizer with a pre-trained embedding model. | |
| Args: | |
| model: The pre-trained embedding model to use for transforming | |
| prompts. | |
| """ | |
| self.model = model | |
| def transform(self, prompts: Sequence[str]) -> np.ndarray: | |
| """Transform texts into numerical vectors using the specified | |
| model. | |
| Args: | |
| prompts: The sequence of raw corpus prompts. Returns: | |
| Vectorized | |
| prompts as a numpy array. | |
| """ | |
| return self.model.encode(prompts) | |