cognitive-engine 0.2.3__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.
Files changed (70) hide show
  1. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/PKG-INFO +1 -1
  2. cognitive_engine-0.2.5/cognitive_engine/nlp/trainer.py +224 -0
  3. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/utils/text.py +3 -0
  4. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/PKG-INFO +1 -1
  5. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/pyproject.toml +1 -1
  6. cognitive_engine-0.2.3/cognitive_engine/nlp/trainer.py +0 -95
  7. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/README.md +0 -0
  8. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/__init__.py +0 -0
  9. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/adapters/__init__.py +0 -0
  10. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/adapters/plastic_numeric_adapter.py +0 -0
  11. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/api/__init__.py +0 -0
  12. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/api/service.py +0 -0
  13. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/compression/__init__.py +0 -0
  14. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/compression/knowledge_compressor.py +0 -0
  15. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/compression/semantic_compressor_v2.py +0 -0
  16. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/config/__init__.py +0 -0
  17. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/config/loader.py +0 -0
  18. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/config/schema.py +0 -0
  19. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/__init__.py +0 -0
  20. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/engine.py +0 -0
  21. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/consolidation/engine_v2.py +0 -0
  22. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/context/__init__.py +0 -0
  23. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/context/long_context.py +0 -0
  24. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/core/__init__.py +0 -0
  25. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/core/builder.py +0 -0
  26. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/core/engine.py +0 -0
  27. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/core/engine_v2.py +0 -0
  28. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/core/registry.py +0 -0
  29. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/core/types.py +0 -0
  30. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/interfaces/__init__.py +0 -0
  31. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/interfaces/base.py +0 -0
  32. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/memory/__init__.py +0 -0
  33. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/memory/graph_memory.py +0 -0
  34. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/memory/hybrid_memory.py +0 -0
  35. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/memory/project_memory.py +0 -0
  36. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/memory/stores.py +0 -0
  37. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/memory/vector_store.py +0 -0
  38. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/models/__init__.py +0 -0
  39. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/models/stable_core.py +0 -0
  40. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/modules/__init__.py +0 -0
  41. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/modules/importance_evaluator.py +0 -0
  42. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/modules/input_processing.py +0 -0
  43. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/modules/semantic_understanding.py +0 -0
  44. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/nlp/__init__.py +0 -0
  45. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/nlp/models.py +0 -0
  46. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/replay/__init__.py +0 -0
  47. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/replay/buffer.py +0 -0
  48. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/routing/__init__.py +0 -0
  49. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/routing/dynamic_router.py +0 -0
  50. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/routing/learned_router.py +0 -0
  51. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/specialists/__init__.py +0 -0
  52. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/specialists/runtime.py +0 -0
  53. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/stability/__init__.py +0 -0
  54. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/stability/governor.py +0 -0
  55. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/training/__init__.py +0 -0
  56. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/training/online_trainer.py +0 -0
  57. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/utils/__init__.py +0 -0
  58. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/utils/numeric.py +0 -0
  59. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/utils/seeding.py +0 -0
  60. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/utils/telemetry.py +0 -0
  61. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine/utils/visualization.py +0 -0
  62. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/SOURCES.txt +0 -0
  63. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/dependency_links.txt +0 -0
  64. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/requires.txt +0 -0
  65. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/cognitive_engine.egg-info/top_level.txt +0 -0
  66. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/setup.cfg +0 -0
  67. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/tests/test_engine_smoke.py +0 -0
  68. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/tests/test_engine_v2.py +0 -0
  69. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/tests/test_learned_router_v2.py +0 -0
  70. {cognitive_engine-0.2.3 → cognitive_engine-0.2.5}/tests/test_numeric_training.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognitive-engine
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Librería NLP basada en Arquitectura Cognitiva V2 (Aprendizaje Continuo y Memoria).
5
5
  Author-email: bueormnew <dalusx64@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -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
+
@@ -40,6 +40,7 @@ STOPWORDS = {
40
40
 
41
41
  KNOWLEDGE_HINTS = ("aprend", "discover", "descubr", "means", "significa", "detecta", "detects", "prefiero")
42
42
  CORRECTION_HINTS = ("actually", "correccion", "correct", "en realidad", "mejor dicho", "not", "no era")
43
+ TRANSLATION_HINTS = ("translate", "translation", "traduc", "->", "significa", "means")
43
44
 
44
45
 
45
46
  def normalize_text(text: str) -> str:
@@ -64,6 +65,8 @@ def detect_intent(text: str) -> str:
64
65
  return "question"
65
66
  if "prefiero" in lowered or "prefer" in lowered:
66
67
  return "preference"
68
+ if any(marker in lowered for marker in TRANSLATION_HINTS):
69
+ return "knowledge_share"
67
70
  if any(marker in lowered for marker in KNOWLEDGE_HINTS):
68
71
  return "knowledge_share"
69
72
  if len(lowered.split()) <= 3:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cognitive-engine
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: Librería NLP basada en Arquitectura Cognitiva V2 (Aprendizaje Continuo y Memoria).
5
5
  Author-email: bueormnew <dalusx64@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cognitive-engine"
3
- version = "0.2.3"
3
+ version = "0.2.5"
4
4
  description = "Librería NLP basada en Arquitectura Cognitiva V2 (Aprendizaje Continuo y Memoria)."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -1,95 +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
- # "Si ves X, la traduccion es Y"
46
- training_prompt = f"Learn this translation: '{source_text}' -> '{target_text}'"
47
-
48
- # Procesar con aprendizaje activado
49
- # Esto activa: Routing -> Memory Write -> Plastic Learner (si aplica)
50
- response = self.model.engine.process(training_prompt, allow_learning=True)
51
-
52
- global_step += 1
53
-
54
- # Simular batch logging
55
- if global_step % 10 == 0:
56
- learning_status = "✅" if response.learning_applied else "❌"
57
- print(f"Step {global_step} | Learned: {learning_status} | Traces: {len(response.traces)}")
58
-
59
- # Consolidación manual si es requerida por la configuración del trainer
60
- if global_step % consolidation_steps == 0:
61
- print("--> Ejecutando Consolidación Cognitiva (Deep Sleep)...")
62
- report = self.model.engine.consolidator.run()
63
- print(f"--> Consolidación completada. Registros fusionados: {report.merged_records}")
64
-
65
- print("Entrenamiento completado.")
66
-
67
- def evaluate(self):
68
- """
69
- Evalúa el modelo en el dataset de validación sin aplicar aprendizaje.
70
- """
71
- if not self.eval_dataset:
72
- print("No se proporcionó dataset de validación.")
73
- return
74
-
75
- print("\\nIniciando Evaluación Cognitiva...")
76
- correct = 0
77
- total = len(self.eval_dataset)
78
-
79
- for i, example in enumerate(self.eval_dataset):
80
- source_text = example.get("en", example.get("source", ""))
81
- target_text = example.get("es", example.get("target", ""))
82
-
83
- # Inferir usando el método específico si es Traductor
84
- if hasattr(self.model, 'translate'):
85
- prediction = self.model.translate(source_text, allow_learning=False)
86
- else:
87
- prediction = self.model.engine.process(source_text, allow_learning=False).text
88
-
89
- # Evaluación ingenua (en la vida real usaríamos BLEU o exact match complejo)
90
- # El engine V2 devolverá su rationale.
91
- # print(f"Eval - Expected: {target_text} | Got: {prediction[:50]}...")
92
- # Asumiremos siempre un análisis cualitativo o lo guardaremos
93
-
94
- print("Evaluación completada.")
95
- return {"eval_loss": 0.0, "notes": "Cualitative evaluation done."}