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

Uploaded Python 3

File details

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

File metadata

  • Download URL: cfprompt-0.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 910bcbb3bfe572f653960cc35bf582e28db35f282bbc7b251bfb45c2d9e6b029
MD5 8a004b511614b486813c8869d97639b9
BLAKE2b-256 ee5ef6d4c6a45228382916a9036ec2d964b99372d3e9f1e7bb1df1dba1b8522b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: cfprompt-0.1.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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3006425a4e75c21c3b73e6ea2d842e11325e032f35d94b0086aabf14d5e533f4
MD5 b3cb50dca282419365cad4d824954e06
BLAKE2b-256 f4a975d231583f0ea49f1f64b42f508e71510dc3437dbf90831c8d91dd578c0c

See more details on using hashes here.

Provenance

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