Comments (11)
I can reproduce your example on master but do not think that this is really a shap issue here. The following lines already result in similar errors:
>>> model([LONG_ARTICLE])
AttributeError: 'list' object has no attribute 'size'
>>> model(LONG_ARTICLE)
AttributeError: 'str' object has no attribute 'size'
Can you somehow get this to run so that the model actually returns something?
from shap.
I have tried but it didn't work.
from shap.
Okay, this indicates that we do not really have a shap error here since the model is not running at all.
from shap.
The hugging face model works well and generates the output summary.
I have also tried bigbird pegasus model in place of this model it did not work either.
LONG_ARTICLE = """"anxiety affects quality of life in those living
with parkinson 's disease ( pd ) more so than
overall cognitive status , motor deficits , apathy
, and depression [ 13 ] . although anxiety and
depression are often related and coexist in pd
patients , recent research suggests that anxiety
rather than depression is the most prominent and
prevalent mood disorder in pd [ 5 , 6 ] . yet ,
our current understanding of anxiety and its
impact on cognition in pd , as well as its neural
basis and best treatment practices , remains
meager and lags far behind that of depression .
overall , neuropsychiatric symptoms in pd have
been shown to be negatively associated with
cognitive performance .
s = [LONG_ARTICLE]
from transformers import BigBirdPegasusForConditionalGeneration, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("google/bigbird-pegasus-large-pubmed")
model = BigBirdPegasusForConditionalGeneration.from_pretrained("google/bigbird-pegasus-large-pubmed")
import shap
explainer = shap.Explainer(model, tokenizer)
shap_values = explainer(s)
It also throws an error below.
AttributeError: 'numpy.ndarray' object has no attribute 'new_zeros'
Below is the full error trace.
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
1519
1520 def _call_impl(self, *args, **kwargs):
[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *args, **kwargs)
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1528
1529 try:
[/usr/local/lib/python3.10/dist-packages/transformers/models/bigbird_pegasus/modeling_bigbird_pegasus.py](https://localhost:8080/#) in forward(self, input_ids, attention_mask, decoder_input_ids, decoder_attention_mask, head_mask, decoder_head_mask, cross_attn_head_mask, encoder_outputs, past_key_values, inputs_embeds, decoder_inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, return_dict)
2510 )
2511
-> 2512 outputs = self.model(
2513 input_ids,
2514 attention_mask=attention_mask,
[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
1519
1520 def _call_impl(self, *args, **kwargs):
[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *args, **kwargs)
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1528
1529 try:
[/usr/local/lib/python3.10/dist-packages/transformers/models/bigbird_pegasus/modeling_bigbird_pegasus.py](https://localhost:8080/#) in forward(self, input_ids, attention_mask, decoder_input_ids, decoder_attention_mask, head_mask, decoder_head_mask, cross_attn_head_mask, encoder_outputs, past_key_values, inputs_embeds, decoder_inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict)
2364 )
2365
-> 2366 decoder_input_ids = shift_tokens_right(
2367 input_ids, self.config.pad_token_id, self.config.decoder_start_token_id
2368 )
[/usr/local/lib/python3.10/dist-packages/transformers/models/bigbird_pegasus/modeling_bigbird_pegasus.py](https://localhost:8080/#) in shift_tokens_right(input_ids, pad_token_id, decoder_start_token_id)
67 Shift input ids one token to the right.
68 """
---> 69 shifted_input_ids = input_ids.new_zeros(input_ids.shape)
70 shifted_input_ids[:, 1:] = input_ids[:, :-1].clone()
71 shifted_input_ids[:, 0] = decoder_start_token_id
AttributeError: 'numpy.ndarray' object has no attribute 'new_zeros'
I suppose there can be a version mismatch issue.
Can you please suggest what should be done.? Would be very helpful.
from shap.
Can you show me how to generate the output with the model you are using? That's what I tried above but that failed.
from shap.
Following is a piece of code to generate the output using longt5.
!pip install transformers[sentencepiece] datasets sacrebleu rouge_score py7zr -q
LONG_ARTICLE = """"anxiety affects quality of life in those living
with parkinson 's disease ( pd ) more so than
overall cognitive status , motor deficits , apathy
, and depression [ 13 ] . although anxiety and
depression are often related and coexist in pd
patients , recent research suggests that anxiety
rather than depression is the most prominent and
prevalent mood disorder in pd [ 5 , 6 ] . yet ,
our current understanding of anxiety and its
impact on cognition in pd , as well as its neural
basis and best treatment practices , remains
meager and lags far behind that of depression ."""
import torch
from transformers import AutoTokenizer, LongT5ForConditionalGeneration
tokenizer = AutoTokenizer.from_pretrained("Stancld/longt5-tglobal-large-16384-pubmed-3k_steps")
input_ids = tokenizer(LONG_ARTICLE, return_tensors="pt").input_ids
model = LongT5ForConditionalGeneration.from_pretrained("Stancld/longt5-tglobal-large-16384-pubmed-3k_steps", return_dict_in_generate=True)
sequences = model.generate(input_ids).sequences
summary = tokenizer.batch_decode(sequences)
For the second model bigbird pegasus the output can be generated using the code below.
from transformers import BigBirdPegasusForConditionalGeneration, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("google/bigbird-pegasus-large-pubmed")
model = BigBirdPegasusForConditionalGeneration.from_pretrained("google/bigbird-pegasus-large-pubmed")
text = "text article"
inputs = tokenizer(text, return_tensors='pt')
prediction = model.generate(**inputs)
prediction = tokenizer.batch_decode(prediction)
from shap.
Hey I encountered a similar issue. I think the issue is SHAP passed in a numpy array instead of tensor object when calling transformers API.
from shap.
@Yangliule Did you find any solution.?
from shap.
Hey @SVC04, I solved the issue by reverting transformers version and pytorch version. Also, make sure you are using AutoModelForSeq2SeqLM.
from shap.
@Yangliule could you please show the versions that are working?
from shap.
Hey @CloseChoice , I'm using transformers 4.12.0 and torch 1.10. Basically I reverted back to when the text SHAP feature was added.
from shap.
Related Issues (20)
- BUG: Workflow failure on macOS when building 'lightgbm'
- ENH: expose raw feature categories in shap.plots.bar HOT 1
- ENH: Winter Values HOT 4
- [Meta-issue] Release 0.45.1 HOT 5
- BUG: [in version 0.44.0 and 0.45.0] UserWarning: unrecognized nn.Module: Flatten HOT 1
- BUG: 'tuple' object has no attribute 'as_list' HOT 4
- BUG: unable to use SHAP with CUDA support on Windows10/11 machine for calculating Shapley values HOT 1
- Support for KerasClassifier HOT 1
- BUG: Failed in nopython mode pipeline (step: native lowering) float16 HOT 4
- Questions: question about SamplingExplainer HOT 1
- BUG: SHAP values calculated using CPU differ from SHAP values calculated using GPU HOT 5
- BUG: TypeError: ufunc 'isfinite' not supported for the input types HOT 4
- BUG: Additivity check failed HOT 1
- When plotting the shap text it is showing an extra letter(Ġ) before every word. HOT 1
- Demangle pytorch and tensorflow dependencies
- ENH: Python 3.13 Support
- TypeError: In v0.20, force plot now requires the base value as the first parameter! Try shap.plots.force(explainer.expected_value, shap_values) or for multi-output models try shap.plots.force(explainer.expected_value[0], shap_values[0]). HOT 1
- Key not found with shap.TreeExplainer and XGBRegressor HOT 1
- BUG: Unable to Generate SHAP values for a dataframe containing text data trained on lstm model HOT 2
- BUG: Error with SHAP Partial Dependence Plot: ValueError: DataFrame.dtypes for data must be int, float, bool or category
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shap.