cognitive-engine 0.2.4__tar.gz → 0.2.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/PKG-INFO +1 -1
- cognitive_engine-0.2.5/cognitive_engine/nlp/trainer.py +224 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/PKG-INFO +1 -1
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/pyproject.toml +1 -1
- cognitive_engine-0.2.4/cognitive_engine/nlp/trainer.py +0 -100
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/README.md +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/adapters/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/adapters/plastic_numeric_adapter.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/api/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/api/service.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/compression/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/compression/knowledge_compressor.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/compression/semantic_compressor_v2.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/config/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/config/loader.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/config/schema.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/engine.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/engine_v2.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/context/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/context/long_context.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/core/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/core/builder.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/core/engine.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/core/engine_v2.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/core/registry.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/core/types.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/interfaces/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/interfaces/base.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/memory/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/memory/graph_memory.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/memory/hybrid_memory.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/memory/project_memory.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/memory/stores.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/memory/vector_store.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/models/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/models/stable_core.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/importance_evaluator.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/input_processing.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/semantic_understanding.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/nlp/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/nlp/models.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/replay/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/replay/buffer.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/routing/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/routing/dynamic_router.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/routing/learned_router.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/specialists/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/specialists/runtime.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/stability/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/stability/governor.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/training/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/training/online_trainer.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/utils/__init__.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/utils/numeric.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/utils/seeding.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/utils/telemetry.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/utils/text.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/utils/visualization.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/SOURCES.txt +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/dependency_links.txt +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/requires.txt +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/top_level.txt +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/setup.cfg +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/tests/test_engine_smoke.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/tests/test_engine_v2.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/tests/test_learned_router_v2.py +0 -0
- {cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/tests/test_numeric_training.py +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from typing import Optional, Dict, Any, List
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CognitiveTrainer:
|
|
6
|
+
"""
|
|
7
|
+
Loop de entrenamiento continuo para un modelo Cognitive Engine V2.
|
|
8
|
+
|
|
9
|
+
Detecta automáticamente la estructura del dataset para soportar múltiples formatos:
|
|
10
|
+
|
|
11
|
+
- **Pares anidados** (opus_books, wmt, etc.):
|
|
12
|
+
``{'translation': {'en': '...', 'es': '...'}}``
|
|
13
|
+
|
|
14
|
+
- **Pares planos con códigos de idioma**:
|
|
15
|
+
``{'en': '...', 'es': '...'}``
|
|
16
|
+
|
|
17
|
+
- **Campos genéricos**:
|
|
18
|
+
``{'source': '...', 'target': '...'}``
|
|
19
|
+
``{'input': '...', 'output': '...'}``
|
|
20
|
+
``{'text': '...', 'label': '...'}``
|
|
21
|
+
|
|
22
|
+
- **Listas de texto plano** (solo fuente, sin target):
|
|
23
|
+
``{'text': '...'}``
|
|
24
|
+
|
|
25
|
+
- **Pares explícitos** pasados como ``(source, target)`` tuples.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
# Campos genéricos de pares que se intentarán en orden
|
|
29
|
+
_PAIR_FIELD_CANDIDATES = [
|
|
30
|
+
("source", "target"),
|
|
31
|
+
("input", "output"),
|
|
32
|
+
("question", "answer"),
|
|
33
|
+
("text", "label"),
|
|
34
|
+
("sentence1", "sentence2"),
|
|
35
|
+
("premise", "hypothesis"),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
model,
|
|
41
|
+
train_dataset,
|
|
42
|
+
eval_dataset=None,
|
|
43
|
+
args: Dict[str, Any] = None,
|
|
44
|
+
source_lang: str = None,
|
|
45
|
+
target_lang: str = None,
|
|
46
|
+
source_field: str = None,
|
|
47
|
+
target_field: str = None,
|
|
48
|
+
):
|
|
49
|
+
"""
|
|
50
|
+
Args:
|
|
51
|
+
model: El modelo CognitiveModel a entrenar.
|
|
52
|
+
train_dataset: Dataset de entrenamiento. Puede ser un HuggingFace Dataset,
|
|
53
|
+
una lista de dicts, o una lista de tuplas (source, target).
|
|
54
|
+
eval_dataset: Dataset de evaluación opcional.
|
|
55
|
+
args: Configuración del training:
|
|
56
|
+
- ``num_train_epochs`` (int, default 1)
|
|
57
|
+
- ``consolidation_steps`` (int, default 500)
|
|
58
|
+
- ``log_steps`` (int, default 10)
|
|
59
|
+
source_lang: Código de idioma fuente (ej. ``"en"``). Si se especifica,
|
|
60
|
+
buscará directamente este campo o dentro de ``translation``.
|
|
61
|
+
target_lang: Código de idioma objetivo (ej. ``"es"``).
|
|
62
|
+
source_field: Nombre del campo fuente para override manual.
|
|
63
|
+
target_field: Nombre del campo objetivo para override manual.
|
|
64
|
+
"""
|
|
65
|
+
self.model = model
|
|
66
|
+
self.train_dataset = train_dataset
|
|
67
|
+
self.eval_dataset = eval_dataset
|
|
68
|
+
self.args = args or {}
|
|
69
|
+
self.source_lang = source_lang or getattr(model, "source_lang", None)
|
|
70
|
+
self.target_lang = target_lang or getattr(model, "target_lang", None)
|
|
71
|
+
self.source_field = source_field
|
|
72
|
+
self.target_field = target_field
|
|
73
|
+
|
|
74
|
+
# ------------------------------------------------------------------
|
|
75
|
+
# Detección automática de estructura
|
|
76
|
+
# ------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
def _extract_pair(self, example: Any):
|
|
79
|
+
"""
|
|
80
|
+
Extrae el par (source_text, target_text) de cualquier formato de ejemplo.
|
|
81
|
+
Retorna (source_text, target_text) donde target_text puede ser None.
|
|
82
|
+
"""
|
|
83
|
+
# Caso 1: la entrada es una tupla/lista directa (source, target)
|
|
84
|
+
if isinstance(example, (tuple, list)) and len(example) >= 2:
|
|
85
|
+
return str(example[0]), str(example[1])
|
|
86
|
+
|
|
87
|
+
# Caso 2: la entrada es un string plano
|
|
88
|
+
if isinstance(example, str):
|
|
89
|
+
return example, None
|
|
90
|
+
|
|
91
|
+
if not isinstance(example, dict):
|
|
92
|
+
return str(example), None
|
|
93
|
+
|
|
94
|
+
# Caso 3: override manual de campos
|
|
95
|
+
if self.source_field and self.target_field:
|
|
96
|
+
src = example.get(self.source_field, "")
|
|
97
|
+
tgt = example.get(self.target_field, "")
|
|
98
|
+
return str(src), str(tgt) if tgt else None
|
|
99
|
+
|
|
100
|
+
# Caso 4: estructura anidada tipo opus_books/wmt
|
|
101
|
+
# {'translation': {'en': '...', 'es': '...'}}
|
|
102
|
+
if "translation" in example and isinstance(example["translation"], dict):
|
|
103
|
+
trans = example["translation"]
|
|
104
|
+
src_lang = self.source_lang
|
|
105
|
+
tgt_lang = self.target_lang
|
|
106
|
+
# Si no se especificaron idiomas, inferir del primer par de claves
|
|
107
|
+
if not src_lang or not tgt_lang:
|
|
108
|
+
keys = list(trans.keys())
|
|
109
|
+
src_lang = keys[0] if len(keys) > 0 else None
|
|
110
|
+
tgt_lang = keys[1] if len(keys) > 1 else None
|
|
111
|
+
src = trans.get(src_lang, "")
|
|
112
|
+
tgt = trans.get(tgt_lang, "")
|
|
113
|
+
return str(src), str(tgt) if tgt else None
|
|
114
|
+
|
|
115
|
+
# Caso 5: pares planos con códigos de idioma {'en': '...', 'es': '...'}
|
|
116
|
+
if self.source_lang and self.target_lang:
|
|
117
|
+
if self.source_lang in example and self.target_lang in example:
|
|
118
|
+
return str(example[self.source_lang]), str(example[self.target_lang])
|
|
119
|
+
|
|
120
|
+
# Caso 6: campos genéricos conocidos
|
|
121
|
+
for src_field, tgt_field in self._PAIR_FIELD_CANDIDATES:
|
|
122
|
+
if src_field in example:
|
|
123
|
+
src = example[src_field]
|
|
124
|
+
tgt = example.get(tgt_field)
|
|
125
|
+
return str(src), str(tgt) if tgt else None
|
|
126
|
+
|
|
127
|
+
# Caso 7: cualquier campo de texto disponible
|
|
128
|
+
for key, value in example.items():
|
|
129
|
+
if isinstance(value, str) and len(value) > 0:
|
|
130
|
+
return value, None
|
|
131
|
+
|
|
132
|
+
return str(example), None
|
|
133
|
+
|
|
134
|
+
def _build_prompt(self, source: str, target: str | None) -> str:
|
|
135
|
+
"""Construye el prompt de aprendizaje con marcadores que activan el intent correcto."""
|
|
136
|
+
if target:
|
|
137
|
+
if self.source_lang and self.target_lang:
|
|
138
|
+
return f"Learn this translation from {self.source_lang} to {self.target_lang}: '{source}' -> '{target}'"
|
|
139
|
+
return f"Learn this: '{source}' -> '{target}'"
|
|
140
|
+
return f"Learn this: {source}"
|
|
141
|
+
|
|
142
|
+
# ------------------------------------------------------------------
|
|
143
|
+
# Training loop
|
|
144
|
+
# ------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
def train(self):
|
|
147
|
+
"""Inicia el proceso de aprendizaje continuo y consolidación."""
|
|
148
|
+
epochs = self.args.get("num_train_epochs", 1)
|
|
149
|
+
consolidation_steps = self.args.get("consolidation_steps", 500)
|
|
150
|
+
log_steps = self.args.get("log_steps", 10)
|
|
151
|
+
|
|
152
|
+
print(f"Iniciando Cognitive Training por {epochs} épocas...")
|
|
153
|
+
print(f" Dataset size: {len(self.train_dataset)} ejemplos")
|
|
154
|
+
|
|
155
|
+
global_step = 0
|
|
156
|
+
learned_count = 0
|
|
157
|
+
|
|
158
|
+
for epoch in range(epochs):
|
|
159
|
+
print(f"\n--- Época {epoch + 1}/{epochs} ---")
|
|
160
|
+
|
|
161
|
+
for i, example in enumerate(self.train_dataset):
|
|
162
|
+
source_text, target_text = self._extract_pair(example)
|
|
163
|
+
|
|
164
|
+
if not source_text.strip():
|
|
165
|
+
continue
|
|
166
|
+
|
|
167
|
+
training_prompt = self._build_prompt(source_text, target_text)
|
|
168
|
+
|
|
169
|
+
response = self.model.engine.process(
|
|
170
|
+
training_prompt,
|
|
171
|
+
allow_learning=True,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
global_step += 1
|
|
175
|
+
if response.learning_applied:
|
|
176
|
+
learned_count += 1
|
|
177
|
+
|
|
178
|
+
if global_step % log_steps == 0:
|
|
179
|
+
learned_rate = learned_count / global_step * 100
|
|
180
|
+
learning_status = "✅" if response.learning_applied else "❌"
|
|
181
|
+
print(
|
|
182
|
+
f"Step {global_step:>6} | "
|
|
183
|
+
f"Learned: {learning_status} | "
|
|
184
|
+
f"Learn rate: {learned_rate:.1f}% | "
|
|
185
|
+
f"Traces: {len(response.traces)}"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
if global_step % consolidation_steps == 0:
|
|
189
|
+
print(" --> Ejecutando Consolidación Cognitiva (Deep Sleep)...")
|
|
190
|
+
report = self.model.engine.consolidator.run()
|
|
191
|
+
print(f" --> Consolidación completada. Registros fusionados: {report.merged_records}")
|
|
192
|
+
|
|
193
|
+
print(f"\nEntrenamiento completado.")
|
|
194
|
+
print(f" Total steps: {global_step} | Learned: {learned_count} ({learned_count/max(global_step,1)*100:.1f}%)")
|
|
195
|
+
|
|
196
|
+
# ------------------------------------------------------------------
|
|
197
|
+
# Evaluation
|
|
198
|
+
# ------------------------------------------------------------------
|
|
199
|
+
|
|
200
|
+
def evaluate(self):
|
|
201
|
+
"""Evalúa el modelo sin aplicar aprendizaje."""
|
|
202
|
+
if not self.eval_dataset:
|
|
203
|
+
print("No se proporcionó dataset de validación.")
|
|
204
|
+
return
|
|
205
|
+
|
|
206
|
+
print("\nIniciando Evaluación Cognitiva...")
|
|
207
|
+
total = len(self.eval_dataset)
|
|
208
|
+
|
|
209
|
+
for i, example in enumerate(self.eval_dataset):
|
|
210
|
+
source_text, target_text = self._extract_pair(example)
|
|
211
|
+
|
|
212
|
+
if hasattr(self.model, "translate"):
|
|
213
|
+
prediction = self.model.translate(source_text, allow_learning=False)
|
|
214
|
+
else:
|
|
215
|
+
prediction = self.model.engine.process(source_text, allow_learning=False).text
|
|
216
|
+
|
|
217
|
+
if i < 3: # Mostrar algunos ejemplos
|
|
218
|
+
print(f" [{i+1}] Input: {source_text[:80]}")
|
|
219
|
+
print(f" Expected: {(target_text or 'N/A')[:80]}")
|
|
220
|
+
print(f" Got: {prediction[:80]}")
|
|
221
|
+
|
|
222
|
+
print("Evaluación completada.")
|
|
223
|
+
return {"eval_loss": 0.0, "notes": "Qualitative evaluation done."}
|
|
224
|
+
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
from typing import Optional, Dict, Any
|
|
3
|
-
|
|
4
|
-
class CognitiveTrainer:
|
|
5
|
-
"""
|
|
6
|
-
Simula un loop de entrenamiento tradicional para un modelo Cognitive Engine V2.
|
|
7
|
-
A diferencia del fine-tuning de SGD, aquí "entrenar" significa inyectar ejemplos
|
|
8
|
-
en el pipeline cognitivo para que el sistema aprenda plásticamente, actualice su
|
|
9
|
-
memoria y consolide patrones (adaptación de epocas).
|
|
10
|
-
"""
|
|
11
|
-
def __init__(self, model, train_dataset, eval_dataset=None, args=None):
|
|
12
|
-
"""
|
|
13
|
-
Args:
|
|
14
|
-
model (CognitiveModel): El modelo basado en V2 a entrenar.
|
|
15
|
-
train_dataset: Dataset de entrenamiento (ej. HuggingFace Dataset).
|
|
16
|
-
Debe tener campos 'source' y 'target' o similiares.
|
|
17
|
-
eval_dataset: Opcional.
|
|
18
|
-
args (dict): Configuraciones como num_train_epochs, batch_size (simulado).
|
|
19
|
-
"""
|
|
20
|
-
self.model = model
|
|
21
|
-
self.train_dataset = train_dataset
|
|
22
|
-
self.eval_dataset = eval_dataset
|
|
23
|
-
self.args = args or {"num_train_epochs": 1, "consolidation_steps": 100}
|
|
24
|
-
|
|
25
|
-
def train(self):
|
|
26
|
-
"""
|
|
27
|
-
Inicia el proceso de aprendizaje continuo y consolidación emulando epocas.
|
|
28
|
-
"""
|
|
29
|
-
epochs = self.args.get("num_train_epochs", 1)
|
|
30
|
-
consolidation_steps = self.args.get("consolidation_steps", 100)
|
|
31
|
-
|
|
32
|
-
print(f"Iniciando Cognitive Training por {epochs} epocas...")
|
|
33
|
-
|
|
34
|
-
global_step = 0
|
|
35
|
-
for epoch in range(epochs):
|
|
36
|
-
print(f"\\n--- Epoca {epoch + 1}/{epochs} ---")
|
|
37
|
-
|
|
38
|
-
for i, example in enumerate(self.train_dataset):
|
|
39
|
-
# Extraer texto fuente y objetivo (asumiendo estructura genérica)
|
|
40
|
-
# Esto es un ejemplo, se adapta a translation
|
|
41
|
-
source_text = example.get("en", example.get("source", ""))
|
|
42
|
-
target_text = example.get("es", example.get("target", ""))
|
|
43
|
-
|
|
44
|
-
# Creamos un prompt de entrenamiento para el motor cognitivo
|
|
45
|
-
# Incluimos marcadores explícitos de aprendizaje para que el router
|
|
46
|
-
# active el gate de "learn" (knowledge_share intent)
|
|
47
|
-
training_prompt = f"Learn this translation: '{source_text}' -> '{target_text}'"
|
|
48
|
-
|
|
49
|
-
# Procesar con aprendizaje activado.
|
|
50
|
-
# Inyectamos el intent_hint para forzar el camino de aprendizaje
|
|
51
|
-
# sin depender de la detección de texto.
|
|
52
|
-
response = self.model.engine.process(
|
|
53
|
-
training_prompt,
|
|
54
|
-
allow_learning=True,
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
global_step += 1
|
|
58
|
-
|
|
59
|
-
# Simular batch logging
|
|
60
|
-
if global_step % 10 == 0:
|
|
61
|
-
learning_status = "✅" if response.learning_applied else "❌"
|
|
62
|
-
print(f"Step {global_step} | Learned: {learning_status} | Traces: {len(response.traces)}")
|
|
63
|
-
|
|
64
|
-
# Consolidación manual si es requerida por la configuración del trainer
|
|
65
|
-
if global_step % consolidation_steps == 0:
|
|
66
|
-
print("--> Ejecutando Consolidación Cognitiva (Deep Sleep)...")
|
|
67
|
-
report = self.model.engine.consolidator.run()
|
|
68
|
-
print(f"--> Consolidación completada. Registros fusionados: {report.merged_records}")
|
|
69
|
-
|
|
70
|
-
print("Entrenamiento completado.")
|
|
71
|
-
|
|
72
|
-
def evaluate(self):
|
|
73
|
-
"""
|
|
74
|
-
Evalúa el modelo en el dataset de validación sin aplicar aprendizaje.
|
|
75
|
-
"""
|
|
76
|
-
if not self.eval_dataset:
|
|
77
|
-
print("No se proporcionó dataset de validación.")
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
print("\\nIniciando Evaluación Cognitiva...")
|
|
81
|
-
correct = 0
|
|
82
|
-
total = len(self.eval_dataset)
|
|
83
|
-
|
|
84
|
-
for i, example in enumerate(self.eval_dataset):
|
|
85
|
-
source_text = example.get("en", example.get("source", ""))
|
|
86
|
-
target_text = example.get("es", example.get("target", ""))
|
|
87
|
-
|
|
88
|
-
# Inferir usando el método específico si es Traductor
|
|
89
|
-
if hasattr(self.model, 'translate'):
|
|
90
|
-
prediction = self.model.translate(source_text, allow_learning=False)
|
|
91
|
-
else:
|
|
92
|
-
prediction = self.model.engine.process(source_text, allow_learning=False).text
|
|
93
|
-
|
|
94
|
-
# Evaluación ingenua (en la vida real usaríamos BLEU o exact match complejo)
|
|
95
|
-
# El engine V2 devolverá su rationale.
|
|
96
|
-
# print(f"Eval - Expected: {target_text} | Got: {prediction[:50]}...")
|
|
97
|
-
# Asumiremos siempre un análisis cualitativo o lo guardaremos
|
|
98
|
-
|
|
99
|
-
print("Evaluación completada.")
|
|
100
|
-
return {"eval_loss": 0.0, "notes": "Cualitative evaluation done."}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/engine_v2.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/importance_evaluator.py
RENAMED
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/input_processing.py
RENAMED
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/modules/semantic_understanding.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/routing/dynamic_router.py
RENAMED
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/routing/learned_router.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine/training/online_trainer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cognitive_engine-0.2.4 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|