Skip to main content

polalign

An audit framework for LLM alignment with human subgroups, based on polarization. Whose perspective does an LLM's label reflect? When people disagree about a text, a language model's single label sides with someone. polalign finds the texts where annotators are polarized, finds which annotator characteristic (gender, politics, age, ...) explains the split, and measures which side each model takes.

A model must choose a side on a polarized text

The audit in four steps

  1. Detect polarization. Each text gets a DFU score (distance from unimodality). A text with DFU above 0 is polarized.
  2. Attribute it. A polarized text is attributed to a characteristic when every group of that characteristic is internally unimodal (a-posteriori unimodality, AU). Groups in fewer than 10 attributed texts are removed.
  3. Ask the models. Your prompt, your models, optionally with a persona.
  4. Measure alignment. Cohen's kappa between the model's labels and each group's position, with bootstrap intervals and a chance check.

The audit framework

Install

pip install polalign                                  # the AU analysis
pip install "polalign[plots,openai,gemini]"           # figures and the model providers you use

Try it in a minute (no data, no keys)

from polalign import run_dataset
from polalign.toy import toy_spec, toy_ratings

result = run_dataset(toy_spec(), raw=toy_ratings())
print(result.describe())
result.per_dimension        # attributed texts per characteristic

Your own data, prompt and model

from polalign import DatasetSpec, ModelHub, annotate, load_model_inputs, run_dataset, save_au_tables

spec = DatasetSpec(
    name="mydata",
    load=lambda root: my_dataframe,        # columns: item_id, text, rating, plus one column per characteristic
    dimensions={"gender": ("gender", {"m": "man", "f": "woman"}),
                "politics": ("politics", {"l": "left", "r": "right"})},
)
result = run_dataset(spec, raw=my_dataframe, min_au_texts=10)     # min_au_texts=0 keeps all AU texts
save_au_tables({"mydata": result.au}, "results")

def my_prompt(texts, item):
    return f"Rate how toxic each {item} is from 1 to 5.\nFormat: score=<n>, label=<toxic/civil>\n\n{texts}"

annotate(ModelHub.from_env()["chatgpt"], load_model_inputs("results/aposteriori_for_models.csv"), "results", prompt=my_prompt, run="baseline")

Full documentation

This page is the short version. The full documentation lives on GitHub, with nine tutorials (a short document and a runnable notebook each), every parameter, and the code that reproduces the paper:

The paper

This package is the code of Polarization Auditing Framework for LLMs: a Toxicity Detection Study (authors anonymous for review) and follows the current version of the paper.

Metadata

Release files for polalign 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polalign 1.0.0
File Size Uploaded Provenance Actions
polalign-1.0.0.tar.gz 91.6 kB With provenance Details for polalign-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polalign 1.0.0
File Interpreter ABI Platform Actions
polalign-1.0.0-py3-none-any.whl Python 3 none any Details for polalign-1.0.0-py3-none-any.whl

Total release size: 178.3 kB

Release files / polalign-1.0.0.tar.gz

Download URL polalign-1.0.0.tar.gz
Size 91.6 kB
Tags Source
SHA-256 checksum
How to use checksums
803b8c5628b2578e139a957282d3cca01da7b85ecf8e4b5ee6e95a88cfc67a58
BLAKE2b-256 checksum
How to use checksums
5378805dd5f7b9f208588c76b2410bf71ad7dbf3413a923d0fd29117d055f936
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / polalign-1.0.0-py3-none-any.whl

Download URL polalign-1.0.0-py3-none-any.whl
Size 86.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db502d147956b60c67bd0c2af979fcab8305b9770f8a596dbd5ca19abb50093f
BLAKE2b-256 checksum
How to use checksums
61eeff34f581e100db7bfaff7e94b9487f212df898283e4f0d2f58fb0eb845af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for polalign 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for polalign-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page