Skip to main content

Counterfactual prompting with adjusted paraphrase baselines

Project description

cfprompt

Counterfactual prompting with adjusted paraphrase baselines.

Companion package to "Compared to What? Baselines and Metrics for Counterfactual Prompting."

Install

pip install cfprompt   # PyPI release pending; for now:
pip install -e .       # from source clone

Quickstart

import pandas as pd
import cfprompt

df = pd.DataFrame({"question": [...]})

study = cfprompt.Study(
    data=df,
    perturb_column="question",
    target_perturbation=my_swap_function,
    prompt_template="Q: {question}\nA:",
    target_model=cfprompt.HFModel("hf-internal-testing/tiny-random-LlamaForCausalLM"),
    paraphrase_model=cfprompt.OpenAIModel("gpt-4.1"),
    classes=["A", "B", "C", "D"],
    seed=42,
)
report = study.run_all(metrics=["jsd", "flip_rate"])
report.to_excel("results.xlsx")

See examples/ for runnable scripts.

CLI

cfprompt init my_study             # scaffold a starter directory
cfprompt validate config.yaml      # schema check
cfprompt run config.yaml           # execute the study

Security

cfprompt run executes Python code referenced by the config (the target_perturbation and extract_label module:function specs are imported and called). Do not run untrusted YAML files.

Pickle / .pkl files (Study.save / DiskCache): Study.load(path) and a cache_dir populated by another user are equivalent to executing arbitrary Python on load. Never load a .pkl from an untrusted source, and treat cache_dir as user-private (do not point it at a directory another user can write to).

License

MIT.

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

cfprompt-0.1.0.tar.gz (130.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cfprompt-0.1.0-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

Details for the file cfprompt-0.1.0.tar.gz.

File metadata

  • Download URL: cfprompt-0.1.0.tar.gz
  • Upload date:
  • Size: 130.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cfprompt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e29fc9ab3bd19353ef711d459eec68777589afea3796cc13bda10d4a85b7c86b
MD5 a7f6639e8473338a7a2cfe3c3f79b9bc
BLAKE2b-256 11e7ccd2a46bf21d25d35d5247d48fe4ab4810568f2096a415f0e0d3cb8b78de

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfprompt-0.1.0.tar.gz:

Publisher: pypi-publish.yml on redagavin/cfprompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cfprompt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cfprompt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 52.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cfprompt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2443f224505e2ed3334eee52e6cff9d559ae4b95d9b529b97b880acee4ccc57c
MD5 aeeb2b798c77cec7860a074a8fa102ad
BLAKE2b-256 81c5724ef6d866752fff48a23bbd97533740e671af6c4ff4a8d0d12183a0d8e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfprompt-0.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on redagavin/cfprompt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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