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
File size: 1,414 Bytes
33947ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | """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()
|