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

Installation

pip install semanticlens

Quickstart

import semanticlens as sl

# step 1 - preprocess component-visualizations

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,
)
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.evaluate_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 Clear 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.0.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.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semanticlens-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 2d755e26490712bdbe70bab2d012c19d922b025b820abbba27a7de4cf6a77d5a
MD5 23a9c8d275cbd6556b219849c5426b90
BLAKE2b-256 73bc0b9fc28e8d0167a4e8b992f8d8d677d00a0eb15eac9ab16f1265f7ab00a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for semanticlens-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: semanticlens-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee08868a5565224b936f68294bdcb10de071058f1da7309f606a43b6d23cc3aa
MD5 a4d5e96464cd4f47e157d3832760b63c
BLAKE2b-256 2b5b8f4bf9be351203c47d81f981bbc652afc98f6f5ff55f3de7b0f46bd4339a

See more details on using hashes here.

Provenance

The following attestation bundles were made for semanticlens-0.1.0-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