Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens diff view for contrastive attribution methods #193

Merged
merged 1 commit into from
Jun 21, 2023
Merged

Conversation

gsarti
Copy link
Member

@gsarti gsarti commented Jun 21, 2023

Description

This PR adds the original → contrastive label currently used in the PairAggregator to mark tokens that differ between the original generated sequence and the contrast_target when a contrastive attributed_fn is used in model.attribute. Previously, only the original target was shown. This enables to visually assess whether the alignment of contrastive target pair is correct.

Example:

import inseq
import pandas as pd

model = inseq.load_model("Helsinki-NLP/opus-mt-en-it", "saliency")
out = model.attribute(
    "UN peacekeepers",
    "I soldati della pace dell'ONU",
    attributed_fn="contrast_prob_diff",
    contrast_targets="Le forze di pace delle Nazioni Unite"
)
out.show()

image

  • 💥 Breaking change: The TokenWithId items in targets will now have the new text to mark the contrastive step if they differ from the original when a contrastive step function is used. Their id is set to -1 to represent the fact they do not correspond to real tokens.

@gsarti gsarti merged commit 77aa4fc into main Jun 21, 2023
@gsarti gsarti deleted the contrast-tokens branch June 21, 2023 14:06
@gsarti gsarti added this to the v0.5 milestone Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant