Skip to main content

ICA Lens

ICA Lens fits, shares, and applies Independent Component Analysis bases for language-model activations. It can capture activations directly from text or operate on activation tensors supplied by the caller.

uv add icalens

Load a published lens:

from icalens import ICALens

lens = ICALens.from_pretrained("sida/icalens-gpt2-small-pile10k")
result = lens.analyze("She deposited the check at the bank.", layer=6)

result

Fit and publish your own:

icalens fit text \
  --model openai-community/gpt2 \
  --dataset NeelNanda/pile-10k \
  --layers 6 \
  --token-budget 1000 \
  --output ./my-icalens

To publish from the command line, authenticate with hf auth login, set HF_TOKEN, or create a .env file in the current directory containing a Hugging Face token with write permission:

HF_TOKEN=hf_...

Publish a saved lens with:

icalens publish \
  --lens ./my-icalens \
  username/icalens-model-name

Instruction-tuned checkpoints use the same activation-level API and are identified explicitly in their portable metadata:

lens = ICALens(
    model_id="Qwen/Qwen2.5-0.5B-Instruct",
    model_type="instruct",
)

model_type describes the checkpoint and accepts "base" or "instruct". The standard icalens installation can capture and analyze text or completed chat conversations directly. result = lens.analyze(text, layer=6) returns aligned tokens, activations, signed scores, and per-token component energy shares. result.to_html("analysis.html") writes a self-contained interactive explorer; pass metric="energy" to visualize component energy shares instead of scores.

Inputs may be NumPy arrays or PyTorch tensors. Leading dimensions are treated as sample dimensions and the final dimension must be the model hidden size. Fitting uses ICA Lens's built-in PyTorch FastICA implementation and can run on the input tensor's device. NumPy inputs are fitted on CPU. ICA Lens does not depend on scikit-learn or SciPy.

See the documentation for the complete text, conversation, fitting, publishing, and HTML-export workflows.

Run a small GPT-2/Pile-10k fitting check with the installed text command:

icalens fit text \
  --model openai-community/gpt2 \
  --dataset NeelNanda/pile-10k \
  --split train \
  --text-field text \
  --layers 6 \
  --token-budget 1000 \
  --max-iter 20

Fit an instruction-tuned model from UltraChat conversations with:

icalens fit chat \
  --model Qwen/Qwen3.5-2B \
  --layers 12 \
  --token-budget 100000

The source repository retains thin demo/ wrappers for contributors, but they are not required when using the installed package.

Installed-package smoke test

After installing a wheel or PyPI release in a clean project, run the bundled end-to-end check:

uv run icalens smoke-test

By default, the suite checks both public input paths: raw text through the published GPT-2 lens and a formatted conversation through the published Qwen3.5-2B instruct lens. Each case lazily downloads one ICA layer, verifies finite scores and normalized energy, checks reconstruction shape, and writes icalens-smoke-text.html or icalens-smoke-chat.html.

Run only one path when iterating locally:

uv run icalens smoke-test text
uv run icalens smoke-test chat

Use --text-lens, --text-layer, --text-input, --chat-lens, --chat-layer, --chat-input, --chat-response, --device, and --output-dir to override the defaults.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icalens-0.3.0.tar.gz (856.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

icalens-0.3.0-py3-none-any.whl (50.2 kB view details)

Uploaded Python 3

File details

Details for the file icalens-0.3.0.tar.gz.

File metadata

  • Download URL: icalens-0.3.0.tar.gz
  • Upload date:
  • Size: 856.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for icalens-0.3.0.tar.gz
Algorithm Hash digest
SHA256 40aa8fc0ad329587d70acd5e997397af07e592f7bca075a5085f08c8ba006b93
MD5 71c4ee0b78071ba3477833dc66a37732
BLAKE2b-256 fa025dc5280451af675659c2e1311c4a1706e8872356a359166bed9a822164af

See more details on using hashes here.

Provenance

The following attestation bundles were made for icalens-0.3.0.tar.gz:

Publisher: release.yml on liusida/icalens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file icalens-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: icalens-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 50.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for icalens-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c033adce2710aa8c2f03957fe1a47a9d32768ec67d918e66a7378940f9a14404
MD5 65d88f7d4156943057d22ba031bea0da
BLAKE2b-256 5787a599bf46e8c6acb906da2b1a49c5dab81853f1950c9b53b59b2787d79c41

See more details on using hashes here.

Provenance

The following attestation bundles were made for icalens-0.3.0-py3-none-any.whl:

Publisher: release.yml on liusida/icalens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

This release

0.3.0 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

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