Instructions to use hsilvosa/openplacsp-cpv-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use hsilvosa/openplacsp-cpv-classifier with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("hsilvosa/openplacsp-cpv-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
| from pathlib import Path | |
| import joblib | |
| import numpy as np | |
| class CPVDivisionClassifier: | |
| def __init__(self, path: str | Path = "model.joblib"): | |
| self.artifact = joblib.load(path) | |
| def predict(self, texts: list[str], top_k: int = 3): | |
| x = self.artifact["features"].transform(texts) | |
| scores = self.artifact["classifier"].decision_function(x) | |
| calibration = self.artifact["calibration"] | |
| logits = np.clip( | |
| scores * np.asarray(calibration["slopes"]) | |
| + np.asarray(calibration["intercepts"]), | |
| -35.0, | |
| 35.0, | |
| ) | |
| probabilities = 1.0 / (1.0 + np.exp(-logits)) | |
| classes = np.asarray(self.artifact["classes"]) | |
| output = [] | |
| for row in probabilities: | |
| indices = np.argsort(row)[::-1][:top_k] | |
| output.append([ | |
| {"division": str(classes[index]), "probability": float(row[index])} | |
| for index in indices | |
| ]) | |
| return output | |