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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e29fc9ab3bd19353ef711d459eec68777589afea3796cc13bda10d4a85b7c86b
|
|
| MD5 |
a7f6639e8473338a7a2cfe3c3f79b9bc
|
|
| BLAKE2b-256 |
11e7ccd2a46bf21d25d35d5247d48fe4ab4810568f2096a415f0e0d3cb8b78de
|
Provenance
The following attestation bundles were made for cfprompt-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on redagavin/cfprompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfprompt-0.1.0.tar.gz -
Subject digest:
e29fc9ab3bd19353ef711d459eec68777589afea3796cc13bda10d4a85b7c86b - Sigstore transparency entry: 1414031161
- Sigstore integration time:
-
Permalink:
redagavin/cfprompt@97efa44ac0712852d7aceca12a4540ec29287dc5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/redagavin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@97efa44ac0712852d7aceca12a4540ec29287dc5 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2443f224505e2ed3334eee52e6cff9d559ae4b95d9b529b97b880acee4ccc57c
|
|
| MD5 |
aeeb2b798c77cec7860a074a8fa102ad
|
|
| BLAKE2b-256 |
81c5724ef6d866752fff48a23bbd97533740e671af6c4ff4a8d0d12183a0d8e3
|
Provenance
The following attestation bundles were made for cfprompt-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on redagavin/cfprompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cfprompt-0.1.0-py3-none-any.whl -
Subject digest:
2443f224505e2ed3334eee52e6cff9d559ae4b95d9b529b97b880acee4ccc57c - Sigstore transparency entry: 1414031274
- Sigstore integration time:
-
Permalink:
redagavin/cfprompt@97efa44ac0712852d7aceca12a4540ec29287dc5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/redagavin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@97efa44ac0712852d7aceca12a4540ec29287dc5 -
Trigger Event:
push
-
Statement type: