Download scripts/train_model.py from LeonardoMdSA/Context-aware-NLP-classification-platform-with-MCP: direct link, hf CLI and curl.
- Browser
- Download file 772 Bytes
-
https://huggingface.co/spaces/LeonardoMdSA/Context-aware-NLP-classification-platform-with-MCP/resolve/main/scripts/train_model.py
- Command line
-
hf download hf://spaces/LeonardoMdSA/Context-aware-NLP-classification-platform-with-MCP/scripts/train_model.py
-
curl -L -o train_model.py https://huggingface.co/spaces/LeonardoMdSA/Context-aware-NLP-classification-platform-with-MCP/resolve/main/scripts/train_model.py
772 Bytes
| #scripts\train_model.py | |
| from pathlib import Path | |
| import sys | |
| # Add project root to sys.path | |
| sys.path.append(str(Path(__file__).resolve().parent.parent)) | |
| import joblib | |
| from app.classification.sklearn_model import SklearnClassifier | |
| # ------------------------- | |
| # Paths | |
| # ------------------------- | |
| DATASET_PATH = Path(__file__).parent.parent / "data" / "samples" / "training_data.json" | |
| MODEL_PATH = Path(__file__).parent.parent / "models" / "trained_pipeline.joblib" | |
| # ------------------------- | |
| # Train classifier | |
| # ------------------------- | |
| print(f"Loading training data from {DATASET_PATH}") | |
| classifier = SklearnClassifier(dataset_path=str(DATASET_PATH)) | |
| # Save trained pipeline | |
| joblib.dump(classifier.pipeline, MODEL_PATH) | |
| print(f"Trained model saved to {MODEL_PATH}") | |