GodsDevProject commited on
Commit
4a10357
·
verified ·
1 Parent(s): 7ecf278

Create core/vector.py

Browse files
Files changed (1) hide show
  1. core/vector.py +11 -0
core/vector.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import re
3
+
4
+ DIM = 512
5
+
6
+ def embed(text: str) -> np.ndarray:
7
+ v = np.zeros(DIM, dtype=np.float32)
8
+ for w in re.findall(r"[a-zA-Z]{2,}", text.lower()):
9
+ v[hash(w) % DIM] += 1.0
10
+ n = np.linalg.norm(v)
11
+ return v / n if n > 0 else v