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

Add possibility to skip special tokens during attribution #275

Merged
merged 3 commits into from
May 15, 2024

Conversation

gsarti
Copy link
Member

@gsarti gsarti commented May 14, 2024

Description

This PR addresses the possibility of skipping special tokens during attribution using the skip_special_tokens=True argument.

Example usage (regular attribution):

import inseq

model = inseq.load_model("mymusise/CPM-Generate-distill", "integrated_gradients")

out = model.attribute(
    input_texts=["她们是飞行员还是制片人", "她们是飞行员还是制片人"],
    generated_texts=["她们是飞行员还是制片人?", "她们是飞行员还是制片人吗?"],
    step_scores=["probability"],
    skip_special_tokens=True,
)

out.show()

Example usage (contrastive attribution):

import inseq

model = inseq.load_model("mymusise/CPM-Generate-distill", "saliency")

out = model.attribute(
    input_texts="她们是飞行员还是制片人",
    generated_texts="她们是飞行员还是制片人?",
    skip_special_tokens=True, # New argument to skip special tokens
    contrast_targets="她们是飞行员还是制片人吗",
    attributed_fn="contrast_prob_diff",
    step_scores=["probability", "contrast_prob_diff"],
)

out.show()

@gsarti gsarti mentioned this pull request May 14, 2024
1 task
@gsarti gsarti merged commit 96add78 into main May 15, 2024
3 checks passed
@gsarti gsarti deleted the skip-special-tokens branch May 15, 2024 09:34
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