Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- retrain_on_server.py +12 -27
retrain_on_server.py
CHANGED
|
@@ -1,38 +1,23 @@
|
|
| 1 |
import os
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
import numpy as np
|
| 5 |
-
from src.model.classifier import DeceptionClassifier
|
| 6 |
-
from src.utils.config import get_default_config
|
| 7 |
|
| 8 |
def main():
|
| 9 |
print("🚀 STARTING ON-SERVER MODEL RETRAINING...")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
from create_pretrained_model import generate_synthetic_data, train_classifier, train_subject_calibrator
|
| 13 |
-
|
| 14 |
-
config = get_default_config()
|
| 15 |
output_dir = "./models"
|
| 16 |
os.makedirs(output_dir, exist_ok=True)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
classifier.train(X, y)
|
| 28 |
-
|
| 29 |
-
print("3. Saving perfectly matched model...")
|
| 30 |
-
classifier.save(os.path.join(output_dir, "deception_model.pkl"))
|
| 31 |
-
|
| 32 |
-
# Save feature names for reference
|
| 33 |
-
import json
|
| 34 |
-
with open(os.path.join(output_dir, "feature_names.json"), 'w') as f:
|
| 35 |
-
json.dump(classifier.feature_names, f)
|
| 36 |
|
| 37 |
print("✅ RETRAINING COMPLETE! Model is now perfectly synced with server versions.")
|
| 38 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
+
from create_pretrained_model import create_pretrained_model
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def main():
|
| 6 |
print("🚀 STARTING ON-SERVER MODEL RETRAINING...")
|
| 7 |
|
| 8 |
+
# Define output directory
|
|
|
|
|
|
|
|
|
|
| 9 |
output_dir = "./models"
|
| 10 |
os.makedirs(output_dir, exist_ok=True)
|
| 11 |
|
| 12 |
+
# Run the model creation process which:
|
| 13 |
+
# 1. Generates synthetic data
|
| 14 |
+
# 2. Trains the classifier
|
| 15 |
+
# 3. Saves it in the server's native format (fixing version mismatch)
|
| 16 |
+
create_pretrained_model(
|
| 17 |
+
output_dir=output_dir,
|
| 18 |
+
n_samples=2000,
|
| 19 |
+
random_state=42
|
| 20 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
print("✅ RETRAINING COMPLETE! Model is now perfectly synced with server versions.")
|
| 23 |
|