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
| """Export the fitted scikit-learn pipeline for local browser inference.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import joblib | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def export_web_model(model_path: Path, output_path: Path) -> dict[str, object]: | |
| model = joblib.load(model_path) | |
| vectorizer = model.named_steps["tfidf"] | |
| classifier = model.named_steps["classifier"] | |
| vocabulary = dict(sorted(vectorizer.vocabulary_.items(), key=lambda item: item[1])) | |
| payload: dict[str, object] = { | |
| "format": "nwhite-tfidf-logistic-regression-v1", | |
| "classes": [str(label) for label in classifier.classes_], | |
| "vectorizer": { | |
| "vocabulary": vocabulary, | |
| "idf": [float(value) for value in vectorizer.idf_], | |
| "ngram_range": [int(value) for value in vectorizer.ngram_range], | |
| "lowercase": bool(vectorizer.lowercase), | |
| "sublinear_tf": bool(vectorizer.sublinear_tf), | |
| "norm": vectorizer.norm, | |
| }, | |
| "classifier": { | |
| "coef": [[float(value) for value in row] for row in classifier.coef_], | |
| "intercept": [float(value) for value in classifier.intercept_], | |
| }, | |
| } | |
| with output_path.open("w", encoding="utf-8", newline="\n") as handle: | |
| json.dump(payload, handle, ensure_ascii=False, separators=(",", ":")) | |
| handle.write("\n") | |
| return payload | |
| def main() -> None: | |
| payload = export_web_model(ROOT / "model.joblib", ROOT / "web_model.json") | |
| print( | |
| json.dumps( | |
| { | |
| "status": "exported", | |
| "format": payload["format"], | |
| "classes": len(payload["classes"]), | |
| "features": len(payload["vectorizer"]["idf"]), | |
| "output": str(ROOT / "web_model.json"), | |
| }, | |
| indent=2, | |
| ) | |
| ) | |
| if __name__ == "__main__": | |
| main() | |