Skip to main content

A package for mechanistic understanding and validation of large AI model with SemanticLens

Project description

An open-source pytorch implementation of SemanticLens.

arXiv DOI

Installation

pip install semanticlens

Quickstart

import semanticlens as sl

# step 1 - collect component-examples

act_cv = sl.component_visualization.ActivationComponentVisualizer(
    model,
    dataset,
    layer_names,
)
act_cv.run(batch_size=128, num_workers=16)

# step 2 - compute semantic embeddings

fm = sl.foundation_models.OpenClip("hf-hub:apple/MobileCLIP-S2-OpenCLIP")
lens = sl.Lens(
    dataset=dataset,
    component_visualizer=act_cv,
    foundation_model=fm,
    dataset_name="...", # e.g. "imagenet"
    storage_dir="...", # e.g. "cache"
)
lens.compute_semantic_embeddigs(layer_names)

# step 3 - inspect, search, label, evaluate, ...

lens.label(
  ["wall", "small", "sky", "floor", "red",...],
  templates=["a natural image showing {}"],
) # ("layer3", 95): "brown vegetation" ,...

lens.search("watermark") # ("layer4", [63, 21, 362]), ...

lens.eval_clarity() # {"layer4" : [[0.64, 0.32, ... ]]}

Project status

Note
The project is currently under active development. 🛠️
Please expect interfaces to change.

The state of development will be updated here.

Contributing

We adhere to the PEP8 standard with a maximum line width of 120 characters.
For linting and style checks, we use ruff, configured to enforce PEP8 compliance along with additional rules.
Our basic tests are implemented using pytest.

License

BSD 3-Clause License

Citation

@article{dreyer2025mechanistic,
  title={Mechanistic understanding and validation of large AI models with SemanticLens},
  author={Dreyer, Maximilian and Berend, Jim and Labarta, Tobias and Vielhaben, Johanna and Wiegand, Thomas and Lapuschkin, Sebastian and Samek, Wojciech},
  journal={arXiv preprint arXiv:2501.05398},
  year={2025}
}

Project details


Download files

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

Source Distribution

semanticlens-0.1.1.tar.gz (12.9 MB view details)

Uploaded Source

Built Distribution

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

semanticlens-0.1.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file semanticlens-0.1.1.tar.gz.

File metadata

  • Download URL: semanticlens-0.1.1.tar.gz
  • Upload date:
  • Size: 12.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for semanticlens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b62d2e699b238881776e8b75b3f89acdab2f3aaab4432304be3abcd8b941df0e
MD5 3fc24331480dc625278eafafeb958d4e
BLAKE2b-256 cfa1bf1ee3f75b4a1280ee28212c4ad298e1f4e9eb1971108ec9cb753bf9d926

See more details on using hashes here.

Provenance

The following attestation bundles were made for semanticlens-0.1.1.tar.gz:

Publisher: python-publish.yml on jim-berend/semanticlens

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

File details

Details for the file semanticlens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: semanticlens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for semanticlens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 459bbf7bbcd3b793b93cbb32e37911058f68369c65de9feee1c63d6975cb36fc
MD5 b2d3cecf417aeaf2befc90bb06067b60
BLAKE2b-256 ab08bf6491aeb70c18a0ffaf9fbebdeec58620e4507b231c5811f47aa5ea919c

See more details on using hashes here.

Provenance

The following attestation bundles were made for semanticlens-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on jim-berend/semanticlens

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page