diff --git a/.gitignore b/.gitignore index d40bac69..496276e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ lit_nlp/node_modules/** lit_nlp/yarn-error.log -lit_nlp/client/build/** +**/build/** **/__pycache__/** **/*.pyc diff --git a/docs/python_api.md b/docs/python_api.md index 05ca5e17..f4dd973a 100644 --- a/docs/python_api.md +++ b/docs/python_api.md @@ -9,8 +9,8 @@ familarity with the basic [system design](development.md#design-overview) and the [type system](development.md#type-system). The following is intended to give a conceptual overview; for the most precise -documentation, see the code in [lit_nlp/api](../lit_nlp/api) and examples -in [lit_nlp/examples](../lit_nlp/examples). +documentation, see the code in [api](../lit_nlp/api) +and [examples](../lit_nlp/examples). ## Adding Models and Data @@ -44,7 +44,8 @@ and [`Model`](#models) classes implement this, and provide metadata (see the [type system](development.md#type-system)) to describe themselves to other components. -For full examples, see [lit_nlp/examples](../lit_nlp/examples). In particular: +For full examples, see +[examples](../lit_nlp/examples). In particular: * [`simple_tf2_demo.py`](../lit_nlp/examples/simple_tf2_demo.py) for a self-contained Keras/TF2 model for sentiment analysis. @@ -195,8 +196,8 @@ Note: there are a few additional methods in the model API - see The above example defined a black-box model, with predictions but no access to internals. If we want a richer view into the model's behavior, we can add additional return fields corresponding to hidden-state activations, gradients, -or attention. For example, a BERT-based model with several such features might -have the following `output_spec()`: +word embeddings, or attention. For example, a BERT-based model with several such +features might have the following `output_spec()`: ```py def output_spec(self): @@ -249,9 +250,14 @@ Most such components implement the [`Interpreter`](../lit_nlp/api/components.py) API. Conceptually, this is any function that takes a set of datapoints and a model, and produces some output.[^identity-component] For example, -[local gradient-based salience](../lit_nlp/components/gradient_maps.py) +[local gradient-based salience (GradientNorm)](../lit_nlp/components/gradient_maps.py) processes the `TokenGradients` and `Tokens` returned by a model and produces a -list of scores for each token. +list of scores for each token. The Integrated Gradients saliency method +additionally requires a `TokenEmbeddings` input and corresponding output, as +well as a label field `Target` to pin the gradient target to the same class as +an input and corresponding output. See the +[GLUE models class](../lit_nlp/examples/models/glue_models.py) +for an example of these spec requirements. The core API involves implementing the `run()` method: diff --git a/docs/user_guide.md b/docs/user_guide.md index f8c5f0e1..724992a9 100644 --- a/docs/user_guide.md +++ b/docs/user_guide.md @@ -427,7 +427,8 @@ Salience maps show the influence of different parts of inputs features on a model's prediction on the primary selection. This module can contain multiple methodologies for calculating this salience, depending on the capabilities of the model being analyzed (e.x. if the model provides gradients, then -gradient-based token-wise salience can be calculated and displayed). The +gradient-based token-wise salience can be calculated and displayed -- see +[adding models and data](python_api.md#adding-models-and-data) for more). The background of each text piece is colored by the salience of that piece on the prediction, and hovering on any piece will display the exact value calculated for that piece.