Spaces:
Sleeping
Sleeping
Senum2001 commited on
Commit ·
49a9e96
1
Parent(s): 90d4f4d
Fix syntax error: correct indentation for try-except block in run_training_cycle
Browse files
scripts/feedback_learning_pipeline.py
CHANGED
|
@@ -279,86 +279,86 @@ class FeedbackLearningPipeline:
|
|
| 279 |
print(f"[Model Versioning] Warning: Could not capture before state: {e}")
|
| 280 |
before_state = None # Reset to None on error
|
| 281 |
self.version_tracker = None # Disable versioning for this run
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
# Only log training cycle if both states are valid dictionaries
|
| 332 |
-
if (before_state and isinstance(before_state, dict) and
|
| 333 |
-
after_state and isinstance(after_state, dict)):
|
| 334 |
-
# Log the training cycle with before/after comparison
|
| 335 |
-
training_cycle_id = self.version_tracker.log_training_cycle(
|
| 336 |
-
before_state=before_state,
|
| 337 |
-
after_state=after_state,
|
| 338 |
-
feedback_count=len(corrections),
|
| 339 |
-
patterns=patterns,
|
| 340 |
-
performance_metrics=None # TODO: Calculate actual metrics
|
| 341 |
-
)
|
| 342 |
|
| 343 |
-
if
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
return None
|
| 357 |
-
if isinstance(state, dict):
|
| 358 |
-
return state.get("version_id")
|
| 359 |
-
if isinstance(state, str):
|
| 360 |
-
return state
|
| 361 |
-
return None
|
| 362 |
|
| 363 |
return {
|
| 364 |
"status": "success",
|
|
|
|
| 279 |
print(f"[Model Versioning] Warning: Could not capture before state: {e}")
|
| 280 |
before_state = None # Reset to None on error
|
| 281 |
self.version_tracker = None # Disable versioning for this run
|
| 282 |
+
|
| 283 |
+
# Fetch new feedback
|
| 284 |
+
feedback_logs = self.fetch_new_feedback(limit=1000)
|
| 285 |
+
|
| 286 |
+
if not feedback_logs:
|
| 287 |
+
print("[Feedback Pipeline] No new feedback available")
|
| 288 |
+
return {
|
| 289 |
+
"status": "no_feedback",
|
| 290 |
+
"message": "No new feedback to process"
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
# Extract corrections
|
| 294 |
+
corrections = self.extract_corrected_annotations(feedback_logs)
|
| 295 |
+
|
| 296 |
+
if not corrections:
|
| 297 |
+
print("[Feedback Pipeline] No valid corrections found")
|
| 298 |
+
return {
|
| 299 |
+
"status": "no_corrections",
|
| 300 |
+
"message": "No valid corrections extracted"
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
# Analyze patterns
|
| 304 |
+
patterns = self.calculate_correction_patterns(corrections)
|
| 305 |
+
|
| 306 |
+
# Apply adjustments
|
| 307 |
+
self.apply_model_adjustments(patterns)
|
| 308 |
+
|
| 309 |
+
# Update training state
|
| 310 |
+
self.training_state["last_training_time"] = datetime.now().isoformat()
|
| 311 |
+
self.training_state["last_processed_feedback_id"] = feedback_logs[-1].get("created_at")
|
| 312 |
+
self.training_state["total_feedback_processed"] += len(corrections)
|
| 313 |
+
self.training_state["training_runs"].append({
|
| 314 |
+
"timestamp": datetime.now().isoformat(),
|
| 315 |
+
"corrections_processed": len(corrections),
|
| 316 |
+
"patterns": patterns
|
| 317 |
+
})
|
| 318 |
+
|
| 319 |
+
self._save_training_state()
|
| 320 |
+
|
| 321 |
+
# Capture model state AFTER training
|
| 322 |
+
after_state = None
|
| 323 |
+
training_cycle_id = None
|
| 324 |
+
if self.version_tracker and before_state:
|
| 325 |
+
try:
|
| 326 |
+
after_state = self.version_tracker.get_current_model_state()
|
| 327 |
+
self.version_tracker.log_model_version(after_state)
|
| 328 |
+
if after_state and isinstance(after_state, dict):
|
| 329 |
+
print(f"[Model Versioning] Captured state after training: {after_state.get('version_id', 'unknown')[:8]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
+
# Only log training cycle if both states are valid dictionaries
|
| 332 |
+
if (before_state and isinstance(before_state, dict) and
|
| 333 |
+
after_state and isinstance(after_state, dict)):
|
| 334 |
+
# Log the training cycle with before/after comparison
|
| 335 |
+
training_cycle_id = self.version_tracker.log_training_cycle(
|
| 336 |
+
before_state=before_state,
|
| 337 |
+
after_state=after_state,
|
| 338 |
+
feedback_count=len(corrections),
|
| 339 |
+
patterns=patterns,
|
| 340 |
+
performance_metrics=None # TODO: Calculate actual metrics
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
if training_cycle_id:
|
| 344 |
+
print(f"[Training History] Logged training cycle: {training_cycle_id[:8]}...")
|
| 345 |
+
else:
|
| 346 |
+
print(f"[Training History] Skipping cycle logging - invalid state data")
|
| 347 |
+
except Exception as e:
|
| 348 |
+
print(f"[Model Versioning] Error logging version: {e}")
|
| 349 |
+
|
| 350 |
+
print(f"[Feedback Pipeline] Training cycle completed successfully")
|
| 351 |
+
print(f"[Feedback Pipeline] Total feedback processed: {self.training_state['total_feedback_processed']}")
|
| 352 |
+
|
| 353 |
+
# Helper to safely extract version_id whether state is a dict, str, or None
|
| 354 |
+
def _extract_version_id(state):
|
| 355 |
+
if not state:
|
| 356 |
+
return None
|
| 357 |
+
if isinstance(state, dict):
|
| 358 |
+
return state.get("version_id")
|
| 359 |
+
if isinstance(state, str):
|
| 360 |
+
return state
|
| 361 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
return {
|
| 364 |
"status": "success",
|