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.0.1.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.0.1-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cfprompt-0.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 2c749c8802cffe5d68ffc09a131933477fc2de4d6b58374dc6d64952b1e5a9dd
MD5 dfad3f24cbe54a91d165ca5a22c326c4
BLAKE2b-256 8721443ffd9a18fd8269f2f07b540a394b3edbe0096c13fd32c4e96a1c361bf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfprompt-0.0.1.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.0.1-py3-none-any.whl.

File metadata

  • Download URL: cfprompt-0.0.1-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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a23457d0bca8009bb2d3e59163f0c2bb4d64466f629c23678af84a3a2393116b
MD5 5fe99296dfca1edbaa1d60cde10d0169
BLAKE2b-256 6ef71d8344580f661b6a8b43319613a02c8d69e0f7d32cb6a1db9d3567af95f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfprompt-0.0.1-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