Pr🥨mptzl
Turn state-of-the-art LLMs into zero+-shot PyTorch classifiers in just a few lines of code.
Promptzl offers:
- 🤖 Zero+-shot classification with LLMs
- 🤗 Turning causal and masked LMs into classifiers without any training
- 📦 Batch processing on your device for efficiency
- 🚀 Speed-up over calling an online API
- 🔎 Transparency and accessibility by using the model locally
- 📈 Distribution over labels
- ✂️ No need to extract the predictions from the answer.
For more information, check out the official documentation.
Installation
pip install -U promptzl
Getting Started
In just a few lines of code, you can transform a LLM of choice into an old-school classifier with all it's desirable properties:
Set up the dataset:
from datasets import Dataset
dataset = Dataset.from_dict(
{
'text': [
"The food was absolutely wonderful, from preparation to presentation, very pleasing.",
"The service was a bit slow, but the food made up for it. Highly recommend the pasta!",
"The restaurant was too noisy and the food was mediocre at best. Not worth the price.",
],
'label': [1, 1, 0]
}
)
Define a prompt for guiding the language model to the correct predictions:
from promptzl import FnVbzPair, Vbz
prompt = FnVbzPair(
lambda e: f"""Restaurant review classification into categories 'positive' or 'negative'.
'Best pretzls in town!'='positive'
'Rude staff, horrible food.'='negative'
'{e['text']}'=""",
Vbz({0: ["negative"], 1: ["positive"]}))
Initialize a model:
from promptzl import CausalLM4Classification
model = CausalLM4Classification(
'HuggingFaceTB/SmolLM2-1.7B',
prompt=prompt)
Classify the data:
from sklearn.metrics import accuracy_score
output = model.classify(dataset, show_progress_bar=True, batch_size=1)
accuracy_score(dataset['label'], output.predictions)
1.0
For more detailed tutorials, check out the documentation!
Metadata
Release files for promptzl 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| promptzl-1.0.0.tar.gz | 25.4 kB | Without provenance | Details for promptzl-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptzl-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for promptzl-1.0.0-py3-none-any.whl |
Total release size: 45.9 kB
Release files / promptzl-1.0.0.tar.gz
| Download URL | promptzl-1.0.0.tar.gz |
|---|---|
| Size | 25.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88687944e7a2f7e0cebae61d31e918c7d4d59d2d877d8382a275fa030951cf9f
|
|
BLAKE2b-256 checksum How to use checksums |
a4e70421bb579b961f189316658594b670412479220e6ddc30a363a9511b231f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.0 CPython/3.12.7
|
Release files / promptzl-1.0.0-py3-none-any.whl
| Download URL | promptzl-1.0.0-py3-none-any.whl |
|---|---|
| Size | 20.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38fef5923093501dc852f7238e90d9f2e5c18aece27eea2ada183ab662498450
|
|
BLAKE2b-256 checksum How to use checksums |
15a0379ae2619a2afabaee69404f2e751cfe62f63512217030f781c7c9f2e493
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.0 CPython/3.12.7
|
Security for promptzl 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.