Instructions to use Zipeng365/WISP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Zipeng365/WISP with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Zipeng365/WISP", "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
Download src/wisp_fast/parallel.py from Zipeng365/WISP: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/Zipeng365/WISP/resolve/main/src/wisp_fast/parallel.py
- Command line
-
hf download hf://Zipeng365/WISP/src/wisp_fast/parallel.py
-
curl -L -o parallel.py https://huggingface.co/Zipeng365/WISP/resolve/main/src/wisp_fast/parallel.py
1.62 kB
| """Threaded row-local work; sequence decoding is performed once on complete emissions.""" | |
| from concurrent.futures import ThreadPoolExecutor | |
| from contextvars import copy_context | |
| import numpy as np | |
| from threadpoolctl import threadpool_limits | |
| from wisp.cpu.probability import labels_from_proba | |
| from wisp_release.checkpoints import require_sequence_metadata | |
| def parallel_rows(fn, X, workers): | |
| if not isinstance(workers,(int,np.integer)) or workers < 1: | |
| raise ValueError("workers must be a positive integer") | |
| workers=min(workers,max(1,len(X)//32)) | |
| if workers==1: | |
| return fn(X) | |
| bounds=np.linspace(0,len(X),workers+1,dtype=np.intp) | |
| with threadpool_limits(limits=1, user_api="blas"), ThreadPoolExecutor(max_workers=workers) as pool: | |
| jobs=[pool.submit(copy_context().run,fn,X[a:b]) for a,b in zip(bounds[:-1],bounds[1:])] | |
| first=jobs[0].result() | |
| out=np.empty((len(X),*first.shape[1:]),dtype=first.dtype) | |
| out[:bounds[1]]=first | |
| for a,b,job in zip(bounds[1:-1],bounds[2:],jobs[1:]): | |
| out[a:b]=job.result() | |
| return out | |
| def predict_parallel(model,X,*,groups=None,time_index=None,workers=4): | |
| if getattr(model,"feature_workers",1)>1: | |
| raise ValueError("Use either model feature workers or outer prediction workers") | |
| groups,time_index=require_sequence_metadata(model,groups,time_index,n=len(X)) | |
| P=parallel_rows(model.predict_proba,np.asarray(X),workers) | |
| if model.smoother_ is None: | |
| return labels_from_proba(P,model.classes_) | |
| return model.smoother_.predict_from_proba(P,groups=groups,time_index=time_index) | |