Skip to content

Commit fa9add1

Browse files
authored
Step functions fixes, add in_context_pvi (#223)
1 parent a1bb881 commit fa9add1

File tree

6 files changed

+240
-118
lines changed

6 files changed

+240
-118
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,15 @@ Use the `inseq.list_feature_attribution_methods` function to list all available
159159
Step functions are used to extract custom scores from the model at each step of the attribution process with the `step_scores` argument in `model.attribute`. They can also be used as targets for attribution methods relying on model outputs (e.g. gradient-based methods) by passing them as the `attributed_fn` argument. The following step functions are currently supported:
160160

161161
- `logits`: Logits of the target token.
162-
- `probability`: Probability of the target token.
162+
- `probability`: Probability of the target token. Can also be used for log-probability by passing `logprob=True`.
163163
- `entropy`: Entropy of the predictive distribution.
164164
- `crossentropy`: Cross-entropy loss between target token and predicted distribution.
165165
- `perplexity`: Perplexity of the target token.
166-
- `contrast_prob`: Probability of the target token when different contrastive inputs are provided to the model. Equivalent to `probability` when no contrastive inputs are provided.
166+
- `contrast_logits`/`contrast_prob`: Logits/probabilities of the target token when different contrastive inputs are provided to the model. Equivalent to `logits`/`probability` when no contrastive inputs are provided.
167+
- `contrast_logits_diff`/`contrast_prob_diff`: Difference in logits/probability between original and foil target tokens pair, can be used for contrastive evaluation as in [contrastive attribution](https://aclanthology.org/2022.emnlp-main.14/) (Yin and Neubig, 2022).
167168
- `pcxmi`: Point-wise Contextual Cross-Mutual Information (P-CXMI) for the target token given original and contrastive contexts [(Yin et al. 2021)](https://arxiv.org/abs/2109.07446).
168169
- `kl_divergence`: KL divergence of the predictive distribution given original and contrastive contexts. Can be restricted to most likely target token options using the `top_k` and `top_p` parameters.
169-
- `contrast_prob_diff`: Difference in probability between original and foil target tokens pair, can be used for contrastive evaluation as in [Contrastive Attribution](https://aclanthology.org/2022.emnlp-main.14/) (Yin and Neubig, 2022).
170+
- `in_context_pvi`: In-context Pointwise V-usable Information (PVI) to measure the amount of contextual information used in model predictions [(Lu et al. 2023)](https://arxiv.org/abs/2310.12300).
170171
- `mc_dropout_prob_avg`: Average probability of the target token across multiple samples using [MC Dropout](https://arxiv.org/abs/1506.02142) (Gal and Ghahramani, 2016).
171172
- `top_p_size`: The number of tokens with cumulative probability greater than `top_p` in the predictive distribution of the model.
172173

docs/source/main_classes/step_functions.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ The following functions can be used out-of-the-box as attribution targets or ste
3737

3838
.. autofunction:: perplexity_fn
3939

40+
.. autofunction:: contrast_logits_fn
41+
4042
.. autofunction:: contrast_prob_fn
4143

44+
.. autofunction:: contrast_logits_diff_fn
45+
46+
.. autofunction:: contrast_prob_diff_fn
47+
4248
.. autofunction:: pcxmi_fn
4349

4450
.. autofunction:: kl_divergence_fn
4551

46-
.. autofunction:: contrast_prob_diff_fn
52+
.. autofunction:: in_context_pvi_fn
4753

4854
.. autofunction:: mc_dropout_prob_avg_fn
4955

0 commit comments

Comments
 (0)