Metadata-Version: 2.4
Name: crosswise
Version: 0.1.0
Summary: Reliability flags for NLA explanations via independent SAE evidence
Project-URL: Homepage, https://github.com/potatochoudhary/crosswise
License: MIT
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: accelerate
Requires-Dist: huggingface-hub
Requires-Dist: safetensors
Requires-Dist: torch
Requires-Dist: transformers>=4.50
Description-Content-Type: text/markdown

# crosswise

A reliability check for Natural Language Autoencoder (NLA) explanations.

NLAs describe a model's internal activations in English, and they confabulate: on a
212-position benchmark, 40% of the phrases an NLA quoted as being "from the prompt" were
not in the prompt. The model's own confidence does not detect this.

`crosswise` cross-checks each quoted claim against independent evidence from a sparse
autoencoder reading the *same* activation. If the NLA quotes a word and no SAE feature at
that position supports it, the word is flagged.

## What it does, and doesn't

On the benchmark, flagging "no SAE support" caught **83% of fabrications at 67% precision**,
and SAE support separated true from fabricated words by 55 points (72% vs 17%, z = 7.84).

This is a **first-pass reliability flag, not an oracle.** The matcher checks whether a
feature's text label or logit-lens tokens contain a content word from the quote. That is
deliberately simple and it undercounts real support, so:

- an "unsupported" or "fabricated" flag means *worth a second look*, not *proven false*
- SAEs are lossy; absence of a supporting feature is evidence, not proof
- numbers and some names are represented diffusely at layer 41 and check poorly
- only claims about the *input* are checkable this way; claims about the model's cognition are not

## Requirements

A GPU with ~55 GB (gemma-3-27b-it in bf16). Rent one if you need to; this is a research
tool for people already doing mechanistic interpretability. No API key required — the NLA
explanations and SAE feature descriptors both come from Neuronpedia's public endpoints.

## Install

```bash
pip install torch transformers accelerate safetensors huggingface_hub
pip install -e .
```

## Use

```python
from crosswise import ReliabilityChecker

rc = ReliabilityChecker()          # loads gemma-3-27b-it + Gemma Scope 2 SAE (slow, ~55GB)
report = rc.score("The midwife, Hassan, delivered twins before sunrise.", position=7)

for v in report.verdicts:
    print(v.quote, v.flag)         # e.g.  'she delivered twins'  fabricated
```

Pass your own `explanation=` to `score()` to check text you already have, or omit it and
crosswise fetches an NLA explanation from Neuronpedia for you.

## Model details

gemma-3-27b-it, layer 41. NLA source `kitft-l41`, SAE `41-gemmascope-2-res-262k`, both on
Neuronpedia. Full study and method: [blog link].

## Limitations and next steps

The matcher is the weak point and the obvious thing to improve: embedding similarity against
the feature's max-activating examples would beat label-string matching. Extending the check
to claims about model cognition (not just the input) is the direction that matters most for
auditing use, and is not yet supported.

MIT licensed.
