This release is a pre-release and may not be stable for production use.
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)
print(result.tokens)
print(result.scores)
result.to_html("analysis.html")
Fit and publish your own:
from icalens import ICALens
lens = ICALens(
model_id="openai-community/gpt2",
model_type="base",
activation_site="resid_post",
)
lens.fit(activations, layer=6, random_state=0)
lens.save("./my-icalens")
lens.push_to_hub("username/icalens-gpt2-small")
For the standalone publishing demo, create a project-root .env file containing
a Hugging Face token with write permission:
HF_TOKEN=hf_...
The .env file is ignored by Git. Publish a saved lens with:
uv run python demo/publish.py \
--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.
For the 1,000-token GPT-2/Pile-10k fitting demo, run:
uv sync
uv run python demo/fit.py
For the corresponding instruct-model demo using all formatted UltraChat conversation tokens, including template markers, run:
uv run python demo/fit_chat.py --layers 12
Then inspect assistant-token component scores with:
uv run python demo/apply_chat.py
Both apply.py and apply_chat.py also write standalone interactive HTML
explorers under demo/output/; pass --output-file to choose another path.
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
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 icalens-0.3.0.dev1.tar.gz.
File metadata
- Download URL: icalens-0.3.0.dev1.tar.gz
- Upload date:
- Size: 322.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8499d88c8d9d037545900f9623fe80d0653fc87b47e51018ef2caf302527a981
|
|
| MD5 |
e6107a184a4e97cd4b6a7f34c7a58e00
|
|
| BLAKE2b-256 |
3af1293c3218f1b8ef4c3f57b3b8aa8cbbf86fe9e089f4fbb8e258cbe8e96e34
|
Provenance
The following attestation bundles were made for icalens-0.3.0.dev1.tar.gz:
Publisher:
release.yml on liusida/icalens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
icalens-0.3.0.dev1.tar.gz -
Subject digest:
8499d88c8d9d037545900f9623fe80d0653fc87b47e51018ef2caf302527a981 - Sigstore transparency entry: 2429351492
- Sigstore integration time:
-
Permalink:
liusida/icalens@f5c458206d203fd651e06a6f49c745d6a753e70a -
Branch / Tag:
refs/tags/v0.3.0.dev1 - Owner: https://github.com/liusida
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f5c458206d203fd651e06a6f49c745d6a753e70a -
Trigger Event:
release
-
Statement type:
File details
Details for the file icalens-0.3.0.dev1-py3-none-any.whl.
File metadata
- Download URL: icalens-0.3.0.dev1-py3-none-any.whl
- Upload date:
- Size: 32.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7addab216fe32691d324f8dcd3fa6fa944140f7abb675b0318e459255f4d532d
|
|
| MD5 |
c05308b2ff0d41e1f8e5faa86931ef18
|
|
| BLAKE2b-256 |
b144cb83e22a43f1ffadae06bf3a94bf4dbe66ba0182e5052d83e6b9a3f05c4b
|
Provenance
The following attestation bundles were made for icalens-0.3.0.dev1-py3-none-any.whl:
Publisher:
release.yml on liusida/icalens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
icalens-0.3.0.dev1-py3-none-any.whl -
Subject digest:
7addab216fe32691d324f8dcd3fa6fa944140f7abb675b0318e459255f4d532d - Sigstore transparency entry: 2429351549
- Sigstore integration time:
-
Permalink:
liusida/icalens@f5c458206d203fd651e06a6f49c745d6a753e70a -
Branch / Tag:
refs/tags/v0.3.0.dev1 - Owner: https://github.com/liusida
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f5c458206d203fd651e06a6f49c745d6a753e70a -
Trigger Event:
release
-
Statement type: