Skip to content

Commit 11b1748

Browse files
authored
Merge pull request #1410 from PAIR-code/dev
Merge dev to main for v1.1
2 parents 1866bc3 + 9bd3a60 commit 11b1748

File tree

118 files changed

+3456
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3456
-362
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ docs/documentation/.doctrees/**
1515

1616
**/.DS_Store
1717
.dalle-venv/
18+
.tydi-venv/
1819
.venv/
1920
.vscode/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
recursive-include lit_nlp/client/build/default *.js* *.gif *.html *.png *.svg
2+
include lit_nlp/examples/datasets/prompt_examples.jsonl

RELEASE.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
# Learning Interpretability Tool Release Notes
22

3+
## Release 1.1
4+
5+
This release provides the capabilities to interpret and debug the behaviors of
6+
Generative AI models in LIT. Specifically, we added sequence salience, which
7+
explains the impact of the preceding tokens on the generated tokens produced by
8+
the GenAI models. Major changes include:
9+
* An `LM salience` module in the LIT UI that computes generations, tokenization,
10+
and sequence salience on-demand;
11+
* Computation of sequence salience at different granularities, from the smallest
12+
possible level of tokens, to more interpretable larger spans, such as words,
13+
sentences, lines, or paragraphs.
14+
* Support of OSS modeling frameworks, including KerasNLP and Hugging Face
15+
Transformers for sequence salience computation.
16+
This release would not have been possible without the work of our contributors.
17+
Many thanks to:
18+
[Ryan Mullins](https://github.com/RyanMullins),
19+
[Ian Tenney](https://github.com/iftenney),
20+
[Bin Du](https://github.com/bdu91), and
21+
[Cibi Arjun](https://github.com/cpka145).
22+
23+
### New Stuff
24+
* LM salience module in the LIT UI -
25+
[ab294bd](https://github.com/PAIR-code/lit/commit/ab294bd3e15675c0e63e5a16ffe4b8cd4941c94f)
26+
[5cffc4d](https://github.com/PAIR-code/lit/commit/5cffc4d933e611587b00c25861c911d5f734fa22)
27+
[40bb57a](https://github.com/PAIR-code/lit/commit/40bb57a2531257c38137188090a24e70d47581c8)
28+
[d3980cc](https://github.com/PAIR-code/lit/commit/d3980cc5414e1f9be895defc4f967bee8a2480fc)
29+
[406fbc7](https://github.com/PAIR-code/lit/commit/406fbc7690ee72f6f96ecf68f1238822ae8951c2)
30+
[77583e7](https://github.com/PAIR-code/lit/commit/77583e74236aa443a21ad0779b0ab9c023821b93)
31+
[a758f98](https://github.com/PAIR-code/lit/commit/a758f98c5153f23955b0190a75dc1258ba57b645)
32+
* Sequence salience for decoder-only LM, with support for GPT-2 and KerasNLP -
33+
[27e6901](https://github.com/PAIR-code/lit/commit/27e6901164044c0d33658603369a55600da0b202)
34+
[80cf699](https://github.com/PAIR-code/lit/commit/80cf699f92cd77d58cb2a2a60b9314010b1f336c)
35+
[1df3ba8](https://github.com/PAIR-code/lit/commit/1df3ba8449e865edb5806c10c8054c246d1e38e3)
36+
[b6ab352](https://github.com/PAIR-code/lit/commit/b6ab3522b301810cab3c75723f3fe0dabf829577)
37+
[c97a710](https://github.com/PAIR-code/lit/commit/c97a710416538906ea6b269f90264c0602a15593)
38+
* Prompt examples for sequence salience -
39+
[4f19891](https://github.com/PAIR-code/lit/commit/4f1989180ee570642285682f843242be5bffb9ef)
40+
[000c844](https://github.com/PAIR-code/lit/commit/000c84486ed61439c98dbfdd92959bdbb6f5119f)
41+
[34aa110](https://github.com/PAIR-code/lit/commit/34aa110c36fe0c7ec670f06662078d2f572c79c6)
42+
[ca032ff](https://github.com/PAIR-code/lit/commit/ca032ffb3196e71fd0a7a09118635ca6dafc8153)
43+
44+
45+
### Non-breaking Changes, Bug Fixes, and Enhancements
46+
* Improvements to display various fields and their default ranges -
47+
[8a3f366](https://github.com/PAIR-code/lit/commit/8a3f366816833ead164ecfca778b465ef6d074bb)
48+
[e63b674](https://github.com/PAIR-code/lit/commit/e63b67484fc7f4dbfa3484126c355350d2127bf7)
49+
[d274508](https://github.com/PAIR-code/lit/commit/d2745088966c4ac31a3755f55096eeb8193c5a91)
50+
* Allow only displaying the UI layouts provided by users -
51+
[a219863](https://github.com/PAIR-code/lit/commit/a21986342d83ae64d58607e337fab9db7736242a)
52+
* Internal dependency changes -
53+
[f254fa8](https://github.com/PAIR-code/lit/commit/f254fa8500d6267278fa3dc32fb4bbf56beb7cf7)
54+
[724bdee](https://github.com/PAIR-code/lit/commit/724bdee1f9ea45ce998b9031eea4ad1169299efb)
55+
[2138bd9](https://github.com/PAIR-code/lit/commit/2138bd920e72553f9c920ba489962c8649738574)
56+
* Fix issues with adding more than one example from counterfactual generators -
57+
[d4302bd](https://github.com/PAIR-code/lit/commit/d4302bd6bfc7e4c778ba0e96397ac620242a8d21)
58+
* Fix issues with loading `SimpleSentimentModel` -
59+
[ac8ed59](https://github.com/PAIR-code/lit/commit/ac8ed5902a2c96019ea1137b5138d48017fabf4e)
60+
* Notebook widget improvements -
61+
[cdf79eb](https://github.com/PAIR-code/lit/commit/cdf79eb9048be3e6798e916d5e1ac4cc294929b0)
62+
* Docs updates
63+
364
## Release 1.0
465

566
This is a major release, covering many new features and API changes from the
93.7 KB
Loading
79.6 KB
Loading
198 KB
Loading

docs/documentation/_sources/api.md.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,7 @@ _See the [examples](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples)
807807

808808
### Available types
809809

810-
The full set of `LitType`s is defined in
811-
[types.py](https://github.com/PAIR-code/lit/blob/main/lit_nlp/api/types.py), and summarized
810+
The full set of `LitType`s is defined in [types.py](https://github.com/PAIR-code/lit/blob/main/lit_nlp/api/types.py). Numeric types such as `Integer` and `Scalar` have predefined ranges that can be overridden using corresponding `min_val` and `max_val` attributes as seen [here](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/datasets/penguin_data.py;l=19-22;rcl=574999438). The different types available in LIT are summarized
812811
in the table below.
813812

814813
Note: Bracket syntax, such as `<float>[num_tokens]`, refers to the shapes of
@@ -828,7 +827,7 @@ Name | Description
828827
`TokenTopKPreds` | Predicted tokens and their scores, as from a language model or seq2seq model. | `list[list[tuple[str, float]]]`
829828
`Boolean` | Boolean value. | `bool`
830829
`Scalar` | Scalar numeric value. | `float`
831-
`Integer` | Integer value. | `int`
830+
`Integer` | Integer, with a default range from -32768 to +32767. value. | `int`
832831
`ImageBytes` | Image, represented by a base64 encoded string. LIT also provides `JPEGBytes` and `PNGBytes` types for those specific encodings. | `str`
833832
`RegressionScore` | Scalar value, treated as a regression target or prediction. | `float`
834833
`ReferenceScores` | Scores for one or more reference texts. | `list[float]`

docs/documentation/_sources/components.md.txt

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Components and Features
22

3-
<!--* freshness: { owner: 'lit-dev' reviewed: '2023-08-07' } *-->
3+
<!--* freshness: { owner: 'lit-dev' reviewed: '2024-02-20' } *-->
44

55
<!-- [TOC] placeholder - DO NOT REMOVE -->
66

@@ -264,55 +264,9 @@ module in the LIT UI, which allows for comparison of multiple methods at once:
264264
For a demo with a BERT-based classifier, see https://pair-code.github.io/lit/demos/glue.html and navigate to the
265265
"Explanations" tab.
266266

267-
Currently, salience is supported for classification ( `MulticlassPreds`) and
268-
regression (`RegressionScore`) outputs, though we hope to support seq2seq models
269-
soon.
270-
271-
#### Note on Target Selection
272-
273-
For all salience methods, we require that the class to explain is given as a
274-
label field in the input. For example, if the input example is:
275-
276-
```
277-
{"text": "this movie was terrible!", "label": "0"}
278-
```
279-
280-
Our model should return gradients with respect to the class 0. Conversely, we
281-
might want to ask what features would encourage the model to predict a different
282-
class. If we select class 1 from the UI:
283-
284-
![Target Selection](./images/components/salience-target-select.png){w=400px align=center}
285-
286-
Then the model will receive a modified input with this target:
287-
288-
```
289-
{"text": "this movie was terrible!", "label": "1"}
290-
```
291-
292-
To support this, the model should have the label field in the `input_spec`:
293-
294-
```
295-
def input_spec(self) -> types.Spec:
296-
return {
297-
'text': lit_types.TextSegment(),
298-
'label': lit_types.CategoryLabel(..., required=False),
299-
...
300-
}
301-
```
302-
303-
and have an output field which references this using `parent=`:
304-
305-
```
306-
def output_spec(self) -> types.Spec:
307-
return {
308-
'probas': lit_types.MulticlassPreds(..., parent="label"),
309-
...
310-
}
311-
```
312-
313-
You don't have to call the field "label", and it's okay if this field isn't
314-
present in the *dataset* - as long as it's something that the model will
315-
recognize and use as the target to derive gradients.
267+
Currently, salience is supported for classification ( `MulticlassPreds`),
268+
regression (`RegressionScore`) and generation (`GeneratedText` or
269+
`GeneratedTextCandidates`) outputs.
316270

317271
### Gradient Norm
318272

@@ -433,7 +387,84 @@ can increase the number of samples:
433387
LIME works out-of-the-box with any classification (`MulticlassPreds`) or
434388
regression/scoring (`RegressionScore`) model.
435389

436-
### Salience Clustering
390+
### Target Selection on Classification Output
391+
392+
For all salience methods, we require that the class to explain is given as a
393+
label field in the input. For example, if the input example is:
394+
395+
```
396+
{"text": "this movie was terrible!", "label": "0"}
397+
```
398+
399+
Our model should return gradients with respect to the class 0. Conversely, we
400+
might want to ask what features would encourage the model to predict a different
401+
class. If we select class 1 from the UI:
402+
403+
![Target Selection](./images/components/salience-target-select.png){w=400px align=center}
404+
405+
Then the model will receive a modified input with this target:
406+
407+
```
408+
{"text": "this movie was terrible!", "label": "1"}
409+
```
410+
411+
To support this, the model should have the label field in the `input_spec`:
412+
413+
```
414+
def input_spec(self) -> types.Spec:
415+
return {
416+
'text': lit_types.TextSegment(),
417+
'label': lit_types.CategoryLabel(..., required=False),
418+
...
419+
}
420+
```
421+
422+
and have an output field which references this using `parent=`:
423+
424+
```
425+
def output_spec(self) -> types.Spec:
426+
return {
427+
'probas': lit_types.MulticlassPreds(..., parent="label"),
428+
...
429+
}
430+
```
431+
432+
You don't have to call the field "label", and it's okay if this field isn't
433+
present in the *dataset* - as long as it's something that the model will
434+
recognize and use as the target to derive gradients.
435+
436+
### Sequence salience
437+
438+
Sequence salience generalizes the salience methods mentioned above to
439+
text-to-text generative models and explains the impact of the preceding tokens
440+
on the generated tokens. Currently, we support sequence salience computation for
441+
various OSS modeling frameworks, including KerasNLP and Hugging Face
442+
Transformers.
443+
444+
Sequence salience in the LIT UI provides multiple options for analysis,
445+
including:
446+
447+
* running the salience methods on the text from the dataset (target) or from
448+
the model (response).
449+
* computing the sequence salience through [Gradient Norm](#gradient-norm) or
450+
[Gradient-dot-Input](#gradient-dot-input).
451+
* selecting different granularity levels for salience analysis, from the
452+
smallest possible level of tokens, to more interpretable larger spans, such
453+
as words, sentences, lines, or paragraphs.
454+
455+
(a) Options for sequence salience. | (b) Sequence salience visualization.
456+
-------------------------------------------------------------------------------------------------- | ------------------------------------
457+
![Sequence salience selections](./images/components/sequence-salience-selections.png){w=650px align=center} | ![Sequence salience vis](./images/components/sequence-salience-vis.png){w=650px align=center}
458+
459+
460+
**Code:**
461+
462+
* Demo: [`lm_salience_demo.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/lm_salience_demo.py)
463+
* KerasNLP model wrappers: [`instrumented_keras_lms.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/instrumented_keras_lms.py)
464+
* Transformers model wrappers: [`pretrained_lms.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/pretrained_lms.py)
465+
466+
467+
## Salience Clustering
437468

438469
LIT includes a basic implementation of the salience clustering method from
439470
[Ebert et al. 2022](https://arxiv.org/abs/2211.05485), which uses k-means on a
@@ -448,6 +479,18 @@ salience method, and run using the "Apply" button. The result will be a set of
448479
top tokens for each cluster, as in Table 6 of
449480
[the paper](https://arxiv.org/pdf/2211.05485.pdf).
450481

482+
## Tabular Feature Attribution
483+
484+
Tabular feature attribution seeks to understand the importance of a column of
485+
data on a model's predictions. LIT's tabular feature attribution module supports
486+
this analysis using the [SHAP interpreter](https://github.com/slundberg/shap).
487+
Please check out
488+
[our tutorial](https://pair-code.github.io/lit/tutorials/tab-feat-attr/) to
489+
learn more about how to use this module to analyze feature importance in the
490+
[Penguins demo](https://pair-code.github.io/lit/demos/penguins.html).
491+
492+
![Tabular feature attribution module module](./images/components/tabular-feature-attribution.png){w=500px align=center}
493+
451494
## Pixel-based Salience
452495

453496
LIT also supports pixel-based salience methods, for models that take images as

docs/documentation/_sources/index.md.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Learning Interpretability Tool (LIT)
22

3-
<!--* freshness: { owner: 'lit-dev' reviewed: '2022-12-02' } *-->
3+
<!--* freshness: { owner: 'lit-dev' reviewed: '2023-09-26' } *-->
44

55
<!-- [TOC] placeholder - DO NOT REMOVE -->
66

docs/documentation/_static/scripts/furo.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)