Download core/vector.py from GodsDevProject/FOIA_Declassified_Document_Search: direct link, hf CLI and curl.
- Browser
- Download file 263 Bytes
-
https://huggingface.co/spaces/GodsDevProject/FOIA_Declassified_Document_Search/resolve/main/core/vector.py
- Command line
-
hf download hf://spaces/GodsDevProject/FOIA_Declassified_Document_Search/core/vector.py
-
curl -L -o vector.py https://huggingface.co/spaces/GodsDevProject/FOIA_Declassified_Document_Search/resolve/main/core/vector.py
263 Bytes
| import numpy as np | |
| import re | |
| DIM = 512 | |
| def embed(text: str) -> np.ndarray: | |
| v = np.zeros(DIM, dtype=np.float32) | |
| for w in re.findall(r"[a-zA-Z]{2,}", text.lower()): | |
| v[hash(w) % DIM] += 1.0 | |
| n = np.linalg.norm(v) | |
| return v / n if n > 0 else v |