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

Fix transformers #3578

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fix transformers #3578

wants to merge 5 commits into from

Conversation

costrau
Copy link
Contributor

@costrau costrau commented Mar 18, 2024

Overview

Closes #3217

There were two problems when using a current transformer model. The first was fixed in #3536 and resulted in all SHAP values being zero. The second problem is that the list of transformer models is hard-coded, so each new model would require a new entry. Fortunately, the transformers library provides such a list, so I changed the code to check against their lists.

Minimal working example (random model, random question)

import transformers
import shap

pmodel = transformers.pipeline("text-classification", "microsoft/phi-2", trust_remote_code=True)

data = [
    "Alice: Who is the current president of the United States?\nBob:"
]

pmodel.model.config.task_specific_params = dict({ "text-generation":{
    "max_new_tokens":20}})

pmodel.model.config.is_decoder = True
exp = shap.Explainer(pmodel, pmodel.tokenizer)
shap_values = exp(data, max_evals=15)
shap.plots.text(shap_values)

Checklist

  • All pre-commit checks pass.
  • Unit tests added (if fixing a bug or adding a new feature)

@costrau
Copy link
Contributor Author

costrau commented Mar 18, 2024

The failed test looks like a connection problem to me. Can you rerun the pipeline?

@CloseChoice
Copy link
Collaborator

The failed test looks like a connection problem to me. Can you rerun the pipeline?

cc @connortann

Copy link
Collaborator

@CloseChoice CloseChoice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have not checked this thoroughly yet but this looks amazing. Will come back later this week with a more in-depth review.

@CloseChoice CloseChoice mentioned this pull request Mar 26, 2024
4 tasks
@connortann connortann added the bug Indicates an unexpected problem or unintended behaviour label Mar 28, 2024
Copy link

codecov bot commented Mar 28, 2024

Codecov Report

Attention: Patch coverage is 17.24138% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 61.45%. Comparing base (74db96c) to head (aa87aa8).
Report is 1 commits behind head on master.

Files Patch % Lines
shap/models/_topk_lm.py 4.00% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3578      +/-   ##
==========================================
- Coverage   61.46%   61.45%   -0.01%     
==========================================
  Files          90       90              
  Lines       12746    12748       +2     
==========================================
  Hits         7834     7834              
- Misses       4912     4914       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Zero shap values w/ llama-2 models
3 participants