Skip to main content

Promptzl - LLMs as Classifiers

Project description

GitHub - License Docs - GitHub.io Tests Passing

Pr🥨mptzl v0.9.2 (Beta)

Promptzl is a simple library for turning LLMs into traditional PyTorch-based classifiers using the 🤗 Transformers library.

While large generative models are often used and exhibit strong performance, they can be opaque and slow. Promptzl works in batch mode, returns a softmax distribution, and is 100% transparent. All causal and masked language models from the Hugging Face Hub are available in Promptzl.

Check out more in the official documentation.

Installation

Run

pip install promptzl

or clone this repository, navigate to the main folder and run

pip install .

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:

from promptzl import *
from datasets import load_dataset

dataset = load_dataset("SetFit/ag_news")

verbalizer = Vbz({0: ["World"], 1: ["Sports"], 2: ["Business"], 3: ["Tech"]})
prompt = Txt("[Category:") + verbalizer + Txt("] ") + Key()

model = MaskedLM4Classification("roberta-large", prompt)
output = model.classify(dataset['test'], show_progress_bar=True).predictions
sum([int(prd == lbl) for prd, lbl in zip(output, dataset['test']['label'])]) / len(output)
# 0.7986842105263158

Installation (Dev)

pip install -e .

pip install -r test-requirements.txt

To render the documentation, run:

cd docs && pip install -r requirements.txt && cd ..

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptzl-0.9.2.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

promptzl-0.9.2-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file promptzl-0.9.2.tar.gz.

File metadata

  • Download URL: promptzl-0.9.2.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.12.7

File hashes

Hashes for promptzl-0.9.2.tar.gz
Algorithm Hash digest
SHA256 05313df1b8fe311a8e115847ed598aaaca531c83bc0e3de7793ceb8e03c6b21d
MD5 544159f3e08febd77a26536ec1c1ce8f
BLAKE2b-256 109287ca689da354a4d50ca888fb1787149bb2b255e0ba01b891439b93dddc2d

See more details on using hashes here.

File details

Details for the file promptzl-0.9.2-py3-none-any.whl.

File metadata

  • Download URL: promptzl-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.12.7

File hashes

Hashes for promptzl-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c31916c4195dcd83fb7da781ada80e5b2dc7e6af291eedc8c352637fbc8536d5
MD5 8c459ad5952801e7881ed83870c1a407
BLAKE2b-256 973eaefa187b8253aeb2cb96dd425a294db2e4ba69e29d89160daebf270e65a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page