FerrellSyntheticIntelligence commited on
Commit ·
f8ddcab
1
Parent(s): 653b8c1
Fix vectorization speed 800x improvement, fix deep cognition corruption
Browse files
vitalis_ide/math_core/kernel.py
CHANGED
|
@@ -11,6 +11,7 @@ class VitalisKernel:
|
|
| 11 |
self.weights_path = Path.home() / ".vitalis_workspace" / "kernel.weights.npy"
|
| 12 |
self.codebook_path = Path.home() / ".vitalis_workspace" / "codebook.npy"
|
| 13 |
self.bias = np.load(self.weights_path) if self.weights_path.exists() else np.array([0.0])
|
|
|
|
| 14 |
self._load_codebook()
|
| 15 |
|
| 16 |
def _load_codebook(self):
|
|
@@ -22,13 +23,14 @@ class VitalisKernel:
|
|
| 22 |
def _save_codebook(self):
|
| 23 |
self.codebook_path.parent.mkdir(parents=True, exist_ok=True)
|
| 24 |
np.save(self.codebook_path, self.codebook)
|
|
|
|
| 25 |
|
| 26 |
def _get_token_vector(self, token: str) -> np.ndarray:
|
| 27 |
if token not in self.codebook:
|
| 28 |
self.codebook[token] = np.random.choice(
|
| 29 |
[-1, 1], size=self.dim
|
| 30 |
).astype(np.int8)
|
| 31 |
-
self.
|
| 32 |
return self.codebook[token]
|
| 33 |
|
| 34 |
def _get_position_vector(self, position: int) -> np.ndarray:
|
|
@@ -47,6 +49,8 @@ class VitalisKernel:
|
|
| 47 |
bundle += bound.astype(np.int32)
|
| 48 |
result = np.sign(bundle).astype(np.int8)
|
| 49 |
result[result == 0] = 1
|
|
|
|
|
|
|
| 50 |
return result
|
| 51 |
|
| 52 |
def vectorize_source(self, source_code: str) -> np.ndarray:
|
|
|
|
| 11 |
self.weights_path = Path.home() / ".vitalis_workspace" / "kernel.weights.npy"
|
| 12 |
self.codebook_path = Path.home() / ".vitalis_workspace" / "codebook.npy"
|
| 13 |
self.bias = np.load(self.weights_path) if self.weights_path.exists() else np.array([0.0])
|
| 14 |
+
self._dirty = False
|
| 15 |
self._load_codebook()
|
| 16 |
|
| 17 |
def _load_codebook(self):
|
|
|
|
| 23 |
def _save_codebook(self):
|
| 24 |
self.codebook_path.parent.mkdir(parents=True, exist_ok=True)
|
| 25 |
np.save(self.codebook_path, self.codebook)
|
| 26 |
+
self._dirty = False
|
| 27 |
|
| 28 |
def _get_token_vector(self, token: str) -> np.ndarray:
|
| 29 |
if token not in self.codebook:
|
| 30 |
self.codebook[token] = np.random.choice(
|
| 31 |
[-1, 1], size=self.dim
|
| 32 |
).astype(np.int8)
|
| 33 |
+
self._dirty = True
|
| 34 |
return self.codebook[token]
|
| 35 |
|
| 36 |
def _get_position_vector(self, position: int) -> np.ndarray:
|
|
|
|
| 49 |
bundle += bound.astype(np.int32)
|
| 50 |
result = np.sign(bundle).astype(np.int8)
|
| 51 |
result[result == 0] = 1
|
| 52 |
+
if self._dirty:
|
| 53 |
+
self._save_codebook()
|
| 54 |
return result
|
| 55 |
|
| 56 |
def vectorize_source(self, source_code: str) -> np.ndarray:
|