Skip to content

Commit

Permalink
Update docs for Gemma launch.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 609090874
  • Loading branch information
iftenney authored and LIT team committed Feb 21, 2024
1 parent 9bd3a60 commit 962faaa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/demos/lm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<script>
window.location.replace("http://35.190.117.129/");
</script>
</html>
</html>
2 changes: 1 addition & 1 deletion lit_nlp/components/umap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_fit_transform(self):
# Check that the _fitted flag has been flipped.
self.assertTrue(umap_model._fitted)

# Check correctness of the output shape.
# Check that the output shape is correct.
output_np = np.array([o['z'] for o in outputs_list])
shape = output_np.shape
expected_shape = (n, 3)
Expand Down
55 changes: 33 additions & 22 deletions website/sphinx_src/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,36 +433,47 @@ You don't have to call the field "label", and it's okay if this field isn't
present in the *dataset* - as long as it's something that the model will
recognize and use as the target to derive gradients.

### Sequence salience
## Sequence salience

Sequence salience generalizes the salience methods mentioned above to
text-to-text generative models and explains the impact of the preceding tokens
on the generated tokens. Currently, we support sequence salience computation for
various OSS modeling frameworks, including KerasNLP and Hugging Face
Transformers.
Sequence salience generalizes token-based salience to text-to-text models,
allowing you to explain the impact of the prompt tokens on parts of the model
output.

Sequence salience in the LIT UI provides multiple options for analysis,
including:
LIT has a general-purpose sequence salience visualization designed for
left-to-right ("causal") language models. Currently, this works out-of-the-box
with
[GPT-2 models](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/lm_salience_demo.py)
and with the new Gemma LMs via
[this Colab](https://colab.research.google.com/github/google/generative-ai-docs/blob/main/site/en/gemma/docs/lit_gemma.ipynb).

* running the salience methods on the text from the dataset (target) or from
the model (response).
* computing the sequence salience through [Gradient Norm](#gradient-norm) or
[Gradient-dot-Input](#gradient-dot-input).
* selecting different granularity levels for salience analysis, from the
smallest possible level of tokens, to more interpretable larger spans, such
as words, sentences, lines, or paragraphs.
![Sequence salience - sequence selection](./images/components/sequence-salience-1.png){w=650px align=center}

(a) Options for sequence salience. | (b) Sequence salience visualization.
-------------------------------------------------------------------------------------------------- | ------------------------------------
![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}
![Sequence salience - visualization](./images/components/sequence-salience-2.png){w=650px align=center}

The UI supports multiple options for analysis, including:

**Code:**
* Select from pre-defined target sequences, or explain generations from the
model.
* Different salience methods, including [Gradient Norm](#gradient-norm) and
[Gradient-dot-Input](#gradient-dot-input).
* Multiple granularity levels for analysis, from individual sub-word tokens up
to words, sentences, lines, or paragraphs. Quickly switch between different
views to refine your analysis to different parts of a prompt.
* Display density options to enable working with longer sequences, such as
document text, few-shot eaxmples, or chain-of-thought prompts.

* Demo: [`lm_salience_demo.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/lm_salience_demo.py)
* KerasNLP model wrappers: [`instrumented_keras_lms.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/instrumented_keras_lms.py)
* Transformers model wrappers: [`pretrained_lms.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/pretrained_lms.py)
For a walkthrough of how to use sequence salience to debug LLMs, check out the
Responsible Generative AI Toolkit at
https://ai.google.dev/responsible/model_behavior.

**Code:**

* Demo:
[`lm_salience_demo.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/lm_salience_demo.py)
* KerasNLP model wrappers:
[`instrumented_keras_lms.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/instrumented_keras_lms.py)
* Transformers model wrappers:
[`pretrained_lms.py`](https://github.com/PAIR-code/lit/blob/main/lit_nlp/examples/models/pretrained_lms.py)

## Salience Clustering

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.

0 comments on commit 962faaa

Please sign in to comment.