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

Text Counterfactual Explanations #413

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

drobiu
Copy link

@drobiu drobiu commented Mar 22, 2024

Explained in #414:

I'm working on introducing Text Counterfactual Explanations for Language Model Classifier models to CounterfactualExplanations.jl. The method I'm focusing on is Relevance-based Infilling for Textual Counterfactuals (RELITC) Pyhton code, paper. In short, the method generates an explanation for a string (text) classified by an LM Classifier by computing feature attribution per token (score of how much each token contributed to classifying the text to its class), masking the tokens with the highest attribution scores, and filling in the masks using a fine-tuned Conditional Masked Language Model (CMLM).

To have a fully implemented version of RELITC I think we need to have the following (also somewhat tracked in this project):

  • RELITC
    • Feature Attributions
    • Fine-Tuning for LM Classifier
    • Fine-Tuning for CMLM
    • Masking top-K% tokens
    • Infilling masked tokens
      • Left-to-Right infilling
      • Uncertainty-based infilling
    • Beam search for best K parameter
      • Fluency score
      • Edit score

I'm working on those features in a separate branch, with this PR: #413 where I'm still working in a Jupyter Notebook, but I'm planning to introduce the features to the CE.jl architecture.

The generate_counterfactual(x, target, data, M, generator) can be used in the following way:

  • x being the text(s) to explain
  • target being the target class for the CE
  • data being optional data if fine-tuning of the LM Classifier or CMLM
  • M being the LM Classifier to explain
  • and generator being the RELITC method
    so the function signature should be usable in this case as well.

Following the CounterfactualExplanations.jl spirit, we can think of interoperability for other CE methods, such as MiCE, which is a predecessor for RELITC so it should be possible to reuse some of the code.

  • MiCE

@drobiu drobiu mentioned this pull request Mar 22, 2024
13 tasks
@pat-alt pat-alt linked an issue Mar 22, 2024 that may be closed by this pull request
13 tasks
@drobiu drobiu mentioned this pull request Apr 2, 2024
@pat-alt
Copy link
Member

pat-alt commented Jul 4, 2024

@ceferisbarov hope you're well! This is the work-in-progress on CE for LLMs that I mentioned last time we spoke. Might you be interested in supporting @drobiu a bit here?

@ceferisbarov
Copy link
Contributor

@pat-alt Hi! I would love to. Let me review the paper and the original code and I will ping you guys.

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.

Text Counterfactual Explanations
3 participants