Giter VIP home page Giter VIP logo

Comments (11)

CloseChoice avatar CloseChoice commented on May 27, 2024

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.

SVC04 avatar SVC04 commented on May 27, 2024

I have tried but it didn't work.

from shap.

CloseChoice avatar CloseChoice commented on May 27, 2024

Okay, this indicates that we do not really have a shap error here since the model is not running at all.

from shap.

SVC04 avatar SVC04 commented on May 27, 2024

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.

CloseChoice avatar CloseChoice commented on May 27, 2024

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.

SVC04 avatar SVC04 commented on May 27, 2024

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.

Yangliule avatar Yangliule commented on May 27, 2024

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.

SVC04 avatar SVC04 commented on May 27, 2024

@Yangliule Did you find any solution.?

from shap.

Yangliule avatar Yangliule commented on May 27, 2024

Hey @SVC04, I solved the issue by reverting transformers version and pytorch version. Also, make sure you are using AutoModelForSeq2SeqLM.

from shap.

CloseChoice avatar CloseChoice commented on May 27, 2024

@Yangliule could you please show the versions that are working?

from shap.

Yangliule avatar Yangliule commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.