Learning Interpretability Tool (LIT)

raw JSON →
1.3.1 verified Mon Apr 27 auth: no python

LIT (Learning Interpretability Tool) is an open-source platform from PAIR (People + AI Research) at Google for visualizing and understanding machine learning models. Version 1.3.1 supports interpretability of generative AI, including sequence salience for LLMs, and can be deployed on Google Cloud with public container images. Releases occur approximately every 6 months.

pip install lit-nlp
error ImportError: No module named 'lit_nlp'
cause The package was installed as 'lit-nlp' but Python expects 'lit_nlp' (underscore).
fix
Use: pip install lit-nlp and then import lit_nlp (underscore). Or check installation with: pip list | grep lit
error ModuleNotFoundError: No module named 'lit_nlp.lib'
cause After v1.0, some internal modules were moved; 'lit_nlp.lib' no longer exists.
fix
Use correct import paths, e.g., from lit_nlp.api.types import ...
breaking As of v1.0, the Model class has been refactored: _with_metadata methods are removed. Subclasses must implement get_metadata() directly.
fix Replace calls to predict_with_metadata() with separate calls to predict() and get_metadata().
breaking In v0.5, the package name was changed from LIT to LIT (Learning Interpretability Tool). Some internal module paths may differ from older v0.4.x versions.
fix If migrating from v0.4, update imports to use the new lit_nlp namespace and check for removed functions.
deprecated The 'transformer' salience method is deprecated in favor of 'gradient' and 'attention' for sequence salience.
fix Use 'gradient' or 'attention' salience methods instead of 'transformer' when calling model.salience().
gotcha LIT's default salience computation can be slow on CPU for large models. Users often report that the UI appears frozen.
fix Run LIT on a machine with GPU. For development, reduce the dataset size or model complexity.

Launches LIT server with a CoSE dataset and a BERT classifier. Open http://localhost:5432 to interact.

import lit_nlp
from lit_nlp import dev_server
from lit_nlp.examples.datasets import CoSEDataset
from lit_nlp.examples.models import BertClassifier

datasets = {'cose': CoSEDataset()}
models = {'bert': BertClassifier(version='bert-base-uncased')}

dev_server.serve(datasets, models, port=5432)