Skip to main content

In-Context Explainability 360 Toolkit

Project description

ICX logo wide ICX logo wide

License: Apache 2.0 Discussions Issues Docs

Overview

This toolkit provides in-context explanations for LLMs - explanations of the output of an LLM in terms of parts of the input context given to the LLM. It will be useful for both researchers and practitioners who want to understand the reason for a particular generation with respect to the context.

The toolkit features explanation methods, quick start and elaborate example notebooks, tests, and documentation. The quick start notebooks can also be run in Google Colab.

Methods

  1. Multi-Level Explanations for Generative Language Models: Explains generated text by attributing to parts of the input context and quantifying the importance of these parts to the generation. Read Paper Open In Colab

  2. CELL your Model: Contrastive Explanations for Large Language Models: Explains text generation by generating contrastive prompts (i.e., edited version of the input prompt) that elicit responses that differ from the original response according to a pre-defined score. Read Paper Open In Colab

  3. Token Highlighter: Inspecting and Mitigating Jailbreak Prompts for Large Language Models: Explains potential jailbreak threats by highlighting important prompt tokens based on model gradients. Read Paper Open In Colab

Download package from pypi

To make use of ICX360, simply install ICX360 from your package manager, e.g. pip or uv:

uv pip install icx360

Download the spacy models for use in the project

uv run python -m spacy download en_core_web_trf
uv run python -m spacy download en_core_web_trf

Download from repo

Prerequisites

The toolkit can be installed locally using the instructions below. Please ensure sufficient resources (such as GPUs) are available for running the methods.

The toolkit uses uv as the package manager (Python 3.11). Make sure that uv is installed via either:

curl -Ls https://astral.sh/uv/install.sh | sh

or using Homebrew:

brew install astral-sh/uv/uv

or using pip (use this if in Windows):

pip install uv

Installation

Once uv is installed, in Linux or Mac, clone the repo:

git clone git@github.com:IBM/ICX360.git icx360
cd icx360

Ensure that you are inside the icx360 directory (where README.md is located) and run:

uv venv --python 3.12
source .venv/bin/activate
uv pip install .
uv run python -m spacy download en_core_web_trf
uv run python -m spacy download en_core_web_trf

Or in Windows, run:

uv venv --python 3.12
.venv/bin/activate
uv pip install .
uv run python -m spacy download en_core_web_trf
uv run python -m spacy download en_core_web_trf

The package has been tested on Red Hat Enterprise Linux 9.

Quickstart Examples

  1. MExGen Quick Start Open In Colab

  2. CELL Quick Start Open In Colab

  3. Token Highlighter Jailbreak Inspector Quick Start Open In Colab

Find many more examples here.

Tests

We have included a collection of tests that can be used for checking if the installation worked properly. This can be achieved by running the "non-slow" tests:

pytest -m "not slow"

Note that these only test the plumbing and not any realistic functionality.

Those interested in testing the realistic functionality can run the notebooks in the ./examples/ folder or run the "slow and not vllm" tests. These use Hugging Face models that are large enough to meaningfully perform their tasks. Please ensure you have sufficient infrastructure (e.g. GPUs) before running these. Run the "slow and not vllm" tests using:

pytest -m "slow and not vllm"

Finally, if you also have a VLLM model that you would like to test, first enter its parameters in model_catalog in tests/conftest.py and then run:

pytest -m "vllm"

License

ICX360 is provided under Apache 2.0 license.

Contributing

Get involved

Lets form a community around this toolkit! Ask a question, raise an issue, or express interest to contribute in the discussions page.

IBM ❤️ Open Source AI

The first release of ICX360 has been brought to you by IBM in the hope of building a larger community around this topic.

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

icx360-0.1.0.tar.gz (62.8 kB view details)

Uploaded Source

Built Distribution

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

icx360-0.1.0-py3-none-any.whl (91.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: icx360-0.1.0.tar.gz
  • Upload date:
  • Size: 62.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for icx360-0.1.0.tar.gz
Algorithm Hash digest
SHA256 630951d345e3714c89a43367ff9a1f49d30a056d7f2f66b98b76ec59ea13cdf6
MD5 3cacc31c6acf345e5b3f011f030f6eb9
BLAKE2b-256 4dc3047c5719d7f7b99bfb85d9293faab39909008bb6f7b2e4cae299e5cc6e6c

See more details on using hashes here.

File details

Details for the file icx360-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: icx360-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 91.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for icx360-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4a8184f220d478b42e55516ea8829e140cc531f50a90aa5a6fbdbb4d39c8051
MD5 90f89ca7e285a9d65e122fe5cf466756
BLAKE2b-256 c0047a47a997fc971cb8e7a17fd7d89836690c44e7e1df5b31b3ace210a1f0c6

See more details on using hashes here.

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