jalammar / ecco

Explain, analyze, and visualize NLP language models. Ecco creates interactive visualizations directly in Jupyter notebooks explaining the behavior of Transformer-based language models (like GPT2, BERT, RoBERTA, T5, and T0).
https://ecco.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.96k stars 167 forks source link

AttributeError: 'OutputSeq' object has no attribute 'saliency' #86

Open Claus1 opened 1 year ago

Claus1 commented 1 year ago

captum 0.5.0 torch 1.13.0+cu117

Language_Models_and_Ecco_PyData_Khobar.ipynb

text= "The countries of the European Union are:\n1. Austria\n2. Belgium\n3. Bulgaria\n4."
output_3 = lm.generate(text, generate=20, do_sample=True)
output_3.saliency()

AttributeError Traceback (most recent call last) Cell In [13], line 1 ----> 1 output_3.saliency()

AttributeError: 'OutputSeq' object has no attribute 'saliency'

JoaoLages commented 1 year ago

We changed the name, use output_3.primary_attributions() instead. Check here for more options and information.

verazuo commented 1 year ago

After change it to output_3.primary_attributions(), I got following errors:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:3                                                                                    │
│                                                                                                  │
│   1 text= "The countries of the European Union are:\n1. Austria\n2. Belgium\n3. Bulgaria\n4.     │
│   2 output = lm.generate(text, generate=20, do_sample=True)                                      │
│ ❱ 3 output.primary_attributions()                                                                │
│   4                                                                                              │
│                                                                                                  │
│ /home/xxx/anaconda3/envs/py39/lib/python3.9/site-packages/ecco/output.py:252 in                 │
│ primary_attributions                                                                             │
│                                                                                                  │
│   249 │   │   importance_id = position - self.n_input_tokens                                     │
│   250 │   │   tokens = []                                                                        │
│   251 │   │                                                                                      │
│ ❱ 252 │   │   assert attr_method in self.attribution, \                                          │
│   253 │   │   │   f"attr_method={attr_method} not found. Choose one of the following: {list(se   │
│   254 │   │   attribution = self.attribution[attr_method]                                        │
│   255 │   │   for idx, token in enumerate(self.tokens[0]):                                       │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AssertionError: attr_method=grad_x_input not found. Choose one of the following: []

Any ideas?

JoaoLages commented 1 year ago

Right, you need to pass attribution="grad_x_input" in the lm.generate call

verazuo commented 1 year ago

thx, after passing attribution=["grad_x_input"] in the lm.generate(), it works!