Text Classification
Scikit-learn
Joblib
English
scikit-learn
tfidf
logistic-regression
Synthetic
responsible-ai
workflow-automation
Eval Results (legacy)
Instructions to use nwhite-systems/nwhite-ai-operations-intent-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use nwhite-systems/nwhite-ai-operations-intent-classifier with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("nwhite-systems/nwhite-ai-operations-intent-classifier", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
| """Run local, CPU-only inference with the packaged classifier.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import joblib | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def predict(text: str, top_k: int = 3) -> dict[str, object]: | |
| if not text.strip(): | |
| raise ValueError("Request text must not be empty") | |
| model = joblib.load(ROOT / "model.joblib") | |
| predicted = str(model.predict([text])[0]) | |
| probabilities = model.predict_proba([text])[0] | |
| ranked = sorted( | |
| ((str(label), float(probability)) for label, probability in zip(model.classes_, probabilities)), | |
| key=lambda item: item[1], | |
| reverse=True, | |
| ) | |
| return { | |
| "predicted_intent": predicted, | |
| "top_probabilities": [ | |
| {"intent": label, "probability": probability} for label, probability in ranked[:top_k] | |
| ], | |
| "model_version": "1.0.0", | |
| "warning": "Educational synthetic-data classifier; retain human review for operational decisions.", | |
| } | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("text", help="Non-sensitive operational request to classify") | |
| parser.add_argument("--top-k", type=int, default=3, choices=range(1, 9)) | |
| args = parser.parse_args() | |
| print(json.dumps(predict(args.text, args.top_k), indent=2)) | |
| if __name__ == "__main__": | |
| main() | |